分类 linux 下的文章

Shadowsocks快速搭建

wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR.sh

chmod +x shadowsocksR.sh

./shadowsocksR.sh 2>&1 | tee s-s-go.log

三条命令搞定~

Linux开启socks5代理的python脚本

code:

#!/usr/bin/python 
# Filename s5.py 
# Python Dynamic Socks5 Proxy 
# Usage: python s5.py 1080 
# Background Run: nohup python s5.py 1080 & 
# Email: ringzero@557.im 
   
import socket, sys, select, SocketServer, struct, time 
   
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass 
class Socks5Server(SocketServer.StreamRequestHandler): 
    def handle_tcp(self, sock, remote): 
        fdset = [sock, remote] 
        while True: 
            r, w, e = select.select(fdset, [], []) 
            if sock in r: 
                if remote.send(sock.recv(4096)) <= 0: break 
            if remote in r: 
                if sock.send(remote.recv(4096)) <= 0: break 
    def handle(self): 
        try: 
            pass # print 'from ', self.client_address nothing to do. 
            sock = self.connection 
            # 1. Version 
            sock.recv(262) 
            sock.send("\x05\x00"); 
            # 2. Request 
            data = self.rfile.read(4) 
            mode = ord(data[1]) 
            addrtype = ord(data[3]) 
            if addrtype == 1:       # IPv4 
                addr = socket.inet_ntoa(self.rfile.read(4)) 
            elif addrtype == 3:     # Domain name 
                addr = self.rfile.read(ord(sock.recv(1)[0])) 
            port = struct.unpack('>H', self.rfile.read(2)) 
            reply = "\x05\x00\x00\x01" 
            try: 
                if mode == 1:  # 1. Tcp connect 
                    remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
                    remote.connect((addr, port[0])) 
                    pass # print 'To', addr, port[0]  nothing do to. 
                else: 
                    reply = "\x05\x07\x00\x01" # Command not supported 
                local = remote.getsockname() 
                reply += socket.inet_aton(local[0]) + struct.pack(">H", local[1]) 
            except socket.error: 
                # Connection refused 
                reply = '\x05\x05\x00\x01\x00\x00\x00\x00\x00\x00' 
            sock.send(reply) 
            # 3. Transfering 
            if reply[1] == '\x00':  # Success 
                if mode == 1:    # 1. Tcp connect 
                    self.handle_tcp(sock, remote) 
        except socket.error: 
            pass #print 'error' nothing to do . 
        except IndexError: 
            pass 
def main(): 
    filename = sys.argv[0]; 
    if len(sys.argv)<2: 
        print 'usage: ' + filename + ' port' 
        sys.exit() 
    socks_port = int(sys.argv[1]);     
    server = ThreadingTCPServer(('', socks_port), Socks5Server) 
    print 'bind port: %d' % socks_port + ' ok!' 
    server.serve_forever() 
if __name__ == '__main__': 
    main()

使用方法:

python socks5.py port

linux快速搭建VPN教程

前期准备:

操作系统:Centos-5-x86

所需安装文件:http://myvps-scripts.googlecode.com/files/pptpd.sh

1:首先要检测tun/tap是否已经开启:

cat /dev/net/tun
返回File descriptor in bad state则tun已开启

cat /dev/ppp
返回No such device or address则ppp已开启

如果没有开启可以联系VPS供应商开启即可.一般VPS的管理页面应该都有自助开启的功能.

2.下载安装脚本:
wget http://myvps-scripts.googlecode.com/files/pptpd.sh

3.安装:
sh pptpd.sh

如图所示即表示安装成功:
1.png

修改用户或者添加用户在此文件修改:
vi /etc/ppp/chap-secrets

4.开启内核转发:
vim /etc/sysctl.conf
将net.ipv4.ip_forward = 0 //0改为1
保存执行: sysctl -p

就此,VPN即创建完成,非常简单.

创建VPN连接方法:传送门