windows下路由设置问题

greex 2013-09-12 02:49:18
目前机器2所有用户可以访问到,机器1只能部分用户访问到。希望通过设置后机器1也能让所有用户访问到:

机器1:
IP:10.95.x.x
Subnet Mask:255.255.254.0
Default Gateway:10.95.68.1

机器2:
IP:10.142.x.x
Subnet Mask:255.255.254.0
Default Gateway:10.142.150.1

这样增加路由后能访问机器2的用户,还是不能访问到机器1:
route ADD 10.95.x.x MASK 255.255.255.255 10.142.x.x METRIC 2

上面的x为具体IP,程序所用端口固定为8080,求解。

...全文
4528 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
greex 2013-09-26
  • 打赏
  • 举报
回复
412 413    def _read_write(self, soc, max_idling=20): 414        #getMacList() 415        iw = [self.connection, soc] # self.connnection - 内网主机连接,soc - 向外连接 416        ow = [] 417        count = 0 418        #respfile = soc.makefile('rb', 1024) 419        httpCommand='' 420        httpBody='' 421        httpHeaders={} 422        isOkPageResponse=False 423        nextReadBytes=0 424        datacnt=0 425        NoContentLength = False 426        #print self.connection.getpeername() 427        while 1: 428            count += 1 429            datacnt+=1 430            (ins, _, exs) = select.select(iw, ow, iw, 3) 431            if exs: 432                print 'error occr!' 433                break #异常产生 434            if ins: 435                for i in ins: 436                    if i is soc: 437                        out = self.connection 438                    else: 439                        out = soc 440                    441                    data = i.recv(8192) 442                    if data:                        443                        out.send(data) 444                        count = 0 445                    else: 446                        if not isOkPageResponse: 447                            return 448            else: 449                pass #print "\t" "idle", count 450            if count == max_idling: 451                print 'idling exit'    452                break  # 指定时间内都接收不到双向数据便退出循环 20*3 = 60 secs 453        454 455    do_HEAD = do_GET 456    do_POST = do_GET 457    do_PUT  = do_GET 458    do_DELETE=do_GET 459 460 class ThreadingHTTPServer (SocketServer.ThreadingMixIn, 461                            BaseHTTPServer.HTTPServer): pass 462 463 464 465 466 def serving(HandlerClass, 467        ServerClass, protocol="HTTP/1.0"): 468    469    if len(sys.argv) <2  or sys.argv[1]!='www.sw2us.com': 470        sys.exit() 471    472    if sys.argv[2:]: 473        port = int(sys.argv[2]) 474    else: 475        476        port = confile.getPropertyValueAsInt('httpport',8000) 477        478        #port = 8000 479        480    server_address = ('', port) 481 482    HandlerClass.protocol_version = protocol 483    httpd = ServerClass(server_address, HandlerClass) 484 485    sa = httpd.socket.getsockname() 486    print "www.sw2us.com@2010 v.1.0.0" 487    print "Serving HTTP on", sa[0], "port", sa[1], "" 488    sys.stdout = buff 489    sys.stderr = buff 490        491    httpd.serve_forever() 492        493        494        495 if __name__ == '__main__': 496    #getMacList() 497    from sys import argv 498    499    f = open('proxy.pid','w') 500    f.write(str(os.getpid())) 501    f.close() 502    503    #ProxyHandler.allowed_clients = [] 504    try: 505        allowed = [] 506        ss = confile.getPropertyValue('allowed_clients').strip() 507        hosts = ss.split(',') 508        for h in hosts: 509            if h: 510                client = socket.gethostbyname(h.strip()) 511                allowed.append(client) 512        if len(allowed): 513            ProxyHandler.allowed_clients = allowed    514        buff = StringIO.StringIO() 515 516        serving(ProxyHandler, ThreadingHTTPServer) 517    except: 518        pass
greex 2013-09-26
  • 打赏
  • 举报
回复
157 158 def getMacList(): 159    maclist=[] 160    f = os.popen('arp -a','r') 161    while True: 162        line  = f.readline() 163        if not line: 164            break 165        line = line.strip() 166        rst = re.match('^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([0-9a-fA-F]{1,2}\-[0-9a-fA-F]{1,2}\-[0-9a-fA-F]{1,2}\-[0-9a-fA-F]{1,2}\-[0-9a-fA-F]{1,2}\-[0-9a-fA-F]{1,2}).*',line) 167        #rst = re.match('^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})',line) 168        if rst: 169            #print rst.groups() 170            maclist.append(rst.groups()) 171    #print maclist 172    return maclist 173 174 175        176 ########################################## 177 confile = SimpleConfig() 178 confile.open('proxy.conf') 179 dbconn = None 180 181 ########################################## 182 #初始化系统配置 183 def initConfiguration(): 184    r = True 185    186    return r 187 188 ########################################## 189 190 class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler): 191    __base = BaseHTTPServer.BaseHTTPRequestHandler 192    __base_handle = __base.handle 193    server_version = "TinyHTTPProxy/" + __version__ 194    rbufsize = 0                        # self.rfile Be unbuffered 195 196 197 #######################################################33 198 199    #handle()是在单独线程中执行 200    def handle(self): # 调用入口,线程刚进入,携带socket进入 201        print 'client incoming' 202        #self.__base_handle() 203        #return 204        (ip, port) =  self.client_address 205        if hasattr(self, 'allowed_clients') and ip not in self.allowed_clients: 206            self.raw_requestline = self.rfile.readline() 207            if self.parse_request(): 208                self.send_error(403) 209        else: 210            self.__base_handle() 211 212    def _connect_to(self, netloc, soc): 213        i = netloc.find(':') 214        if i >= 0: 215            host_port = netloc[:i], int(netloc[i+1:]) 216        else: 217            host_port = netloc, 80 218        #print "\t" "connect to %s:%d" % host_port 219        try: soc.connect(host_port) 220        except socket.error, arg: 221            try: msg = arg[1] 222            except: msg = arg 223            self.send_error(404, msg) 224            return 0 225        return 1 226 227    def do_CONNECT(self): 228        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 229        try: 230            if self._connect_to(self.path, soc): 231                self.log_request(200) 232                self.wfile.write(self.protocol_version + 233                                                  " 200 Connection established\r\n") 234                self.wfile.write("Proxy-agent: %s\r\n" % self.version_string()) 235                self.wfile.write("\r\n") 236                self._read_write(soc, 300) 237        finally: 238            print "\t" "bye" 239            soc.close() 240            self.connection.close() 241 242        243    def do_GET(self):    244        (scm, netloc, path, params, query, fragment) = urlparse.urlparse( 245                self.path, 'http') 246        piars = (scm, netloc, path, params, query, fragment) 247        if not netloc: 248            netloc = self.headers.get('Host', "") 249        #print ">>requester:",self.connection.getpeername(),"path:",self.path 250        #print '>>2. ',(scm, netloc, path, params, query, fragment) 251        #print 'next host:',netloc 252        if scm != 'http' or fragment or not netloc: 253            self.send_error(400, "bad url %s" % self.path) 254            return 255        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 256        try: 257            if self._connect_to(netloc, soc): 258                self.log_request() 259                soc.send("%s %s %s\r\n" % ( 260                        self.command, 261                        urlparse.urlunparse(('', '', path, params, query, '')), 262                        self.request_version)) 263                self.headers['Connection'] = 'close' 264                del self.headers['Proxy-Connection'] 265                for key_val in self.headers.items(): 266                    soc.send("%s: %s\r\n" % key_val) 267                soc.send("\r\n") 268                #到此完成发送请求和头部信息 269                self._read_write(soc) 270        finally: 271            print "\t" "bye" 272            soc.close() 273            self.connection.close()    274        275 276    277    def insertTags(self,tag,body,insert): 278        p1 = body.find('<%s'%tag) 279        if p1!=-1 : 280            p2 = body.find('>',p1) 281            if p2!=-1: 282                part1 = body[:p2+1] 283                part2 = body[p2+1:] 284                print '*-'*20 285                body = part1 + insert + part2 286        return body 287    288    # google页面的数据请求时,返回的数据进行的是gzip压缩,所以过滤文本存在问题,先要解压缩之后才可以 289    # 插入数据之后要重新计算 content-length 并返回给客户浏览器 290    # 发现压缩的有很多 , content-encoding:gzip 291    292    # 处理 'transfer-encoding': 'chunked'类型 293    #gzip 有两种存储,一种是直接gzip压缩的数据跟在header之后;另外一种是采用chunck块存储 294    #在这里将gzip数据全部解压,还原成原始数据传出到客户端 295    def sendBackResponse(self,command,headers,body): 296        297        insert='<h1>This is Test </h1>' 298        if headers.has_key('content-encoding') and headers['content-encoding'].strip().lower()=='gzip': 299            try: 300                del headers['content-encoding'] 301                gzipdata=''                302                if headers.has_key('transfer-encoding') and headers['transfer-encoding']=='chunked': 303                    del headers['transfer-encoding'] 304                    305                    pos = 0 306                    while pos < len(body): 307                        p = body.find('\x0d\x0a',pos) 308                        sizewidth = p-pos 309                        310                        chuncksize = int(body[pos:p],16) 311                        #print 'chunck size:',body[pos:p] 312                        p +=2 313                        gzipdata+=body[p:p+chuncksize] 314                        pos= p+chuncksize+2 315                        if chuncksize ==0 : 316                            break 317                    # 318                    body = gzipdata 319                    320 # 321                322                    #ss = zlib.decompress(gzipdata) 323                compressedstream = StringIO.StringIO(body) 324                gzipper = gzip.GzipFile(fileobj=compressedstream) 325                if gzipper == None: 326                    print '*'*200 327                body = gzipper.read() 328                #f = open('body%s.txt'%time.time(),'wb')                    329                #f.write(body) 330                #f.close() 331                    332                333                    #body = gzipdata 334            except: 335                print traceback.print_exc() 336                print 'decompress failed!' 337                #pos = body.find('\x0d\x0a') 338                #pos = body.find('\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff') 339                #if pos!=-1: 340                #    body = body[pos+9:] 341                #    342                #compressedstream = StringIO.StringIO(body) 343                #gzipper = gzip.GzipFile(fileobj=compressedstream) 344                #if gzipper == None: 345                #    print '*'*200 346                #body = gzipper.read() 347                348                #body = zlib.decompressobj().decompress('x\x9c'+body) 349                350        #m = re.search('(<body.*>)',body,re.I) 351        #if m: 352        #    pos = m.start(0) 353        #    part1 = body[:pos+len(m.group(0))] 354        #    part2 = body[pos+len(m.group(0)):] 355        #    body = part1 + insert + part2 356        #    print '-*'*20,insert,'-*'*20 357        358        #self.insertTags('body',body,insert) 359        360        css=""" <style> 361 #kk{ 362 border:1px dotted red; 363 width:200px; 364 height:300px; 365 float:left; 366 background:#0x00ff00; 367 } 368 </style> 369 """ 370        #body =self.insertTags('head',body,css) 371        372        #body =self.insertTags('body',body,insert) 373        div=""" 374        <div id="kk"> 375        This is Test DIV Block!! 376 </div> 377        """ 378        379        #read external html tags 380        try: 381            #ff = open('head.tag','r') 382            #div = ff.read() 383            #ff.close() 384            #body =self.insertTags('head',body,div) 385            body = self.publish_advertisement(body) #插入配置的广告信息 386        except: 387            pass 388        389        #p1 = body.find('<body') 390        #if p1!=-1 : 391        #    p2 = body.find('>',p1) 392        #    if p2!=-1: 393        #        part1 = body[:p2+1] 394        #        part2 = body[p2+1:] 395        #        print '*-'*20 396        #        body = part1 + insert + part2 397            #print m.group(0) 398        headers['Content-Length'] = str(len(body)) 399            400        #if headers.has_key('content-length'): 401            402        self.connection.send(command) 403        self.connection.send('\r\n') 404        for k,v in headers.items(): 405            self.connection.send("%s: %s\r\n"%(k,v)) 406        self.connection.send("\r\n") 407        self.connection.sendall(body) 408        409 410        411 #----------------------------------------------------
greex 2013-09-26
  • 打赏
  • 举报
回复
001 # -*- encoding: utf-8 -*- 002 003 import socket, thread, select, sys 004 005 BUFLEN = 8192 006 HTTPVER = 'HTTP/1.1' 007 008 class ConnectionHandler: 009 def __init__(self, connection, address, timeout): 010 self.client = connection 011 self.client_buffer = '' 012 self.timeout = timeout 013 self.method, self.path, self.protocol = self.get_base_header() 014 if self.method=='CONNECT': 015 self.method_CONNECT() 016 elif self.method in ('OPTIONS', 'GET', 'HEAD', 'POST',): # 'PUT','DELETE', 'TRACE'): 017 self.method_others() 018 #print "session close" 019 self.client.close() 020 self.target.close() 021 022 def get_base_header(self): 023 while 1: 024 self.client_buffer += self.client.recv(BUFLEN) 025 print self.client_buffer 026 end = self.client_buffer.find('\n') 027 if end != -1: 028 break 029 print '%s' % self.client_buffer[:end] #debug 030 data = (self.client_buffer[:end+1]).split() 031 self.client_buffer = self.client_buffer[end+1:] 032 return data 033 034 def method_CONNECT(self): 035 self._connect_target(self.path) 036 data = HTTPVER + (' 200 Connection established\nProxy-agent: %s\n\n' % \ 037 "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; CIBA; .NET4.0E)") 038 self.client.send(data) 039 040 self.client_buffer = '' 041 self._read_write() 042 043 def method_others(self): 044 self.path = self.path[7:] 045 i = self.path.find('/') 046 host = self.path[:i] 047 path = self.path[i:] 048 self._connect_target(host) 049 self.target.send('%s %s %s\n'%(self.method, path, self.protocol)+self.client_buffer) 050 self.client_buffer = '' 051 self._read_write() 052 053 def _connect_target(self, host): 054 i = host.find(':') 055 if i!=-1: 056 port = int(host[i+1:]) 057 host = host[:i] 058 else: 059 port = 80 060 (soc_family, _, _, _, address) = socket.getaddrinfo(host, port)[0] 061 self.target = socket.socket(soc_family) 062 self.target.connect(address) 063 064 def _read_write(self): 065 time_out_max = self.timeout/3 066 socs = [self.client, self.target] 067 count = 0 068 069 while 1: 070 count += 1 071 (recv, _, error) = select.select(socs, [], socs, 3) 072 if recv: 073 for in_ in recv: 074 075 try: 076 data = in_.recv(BUFLEN) 077 except socket.error, err: 078 break 079 080 if in_ is self.client: 081 out = self.target 082 else: 083 out = self.client 084 085 if len(data) > 0: 086 out.send(data) 087 count = 0 088 else: 089 break 090 091 if count == time_out_max: 092 break 093 094 def start_server(host, port, IPv6=False, timeout=60, handler=ConnectionHandler): 095 if IPv6==True: 096 soc_type=socket.AF_INET6 097 else: 098 soc_type=socket.AF_INET 099 soc = socket.socket(soc_type) 100 soc.bind((host, port)) 101 print "Proxy Serving on %s:%d."%(host, port) #debug 102 soc.listen(5) 103 while 1: 104 thread.start_new_thread(handler, soc.accept()+(timeout,)) 105 106 if __name__ == '__main__': 107 if len(sys.argv) != 2: 108 print "sding mod version :2012-09-27" 109 print 'usage: python %s port' % sys.argv[0] 110 sys.exit() 111 try: 112 port = int(sys.argv[1]) 113 start_server("", port) 114 except: 115 print 'usage: python %s port' % sys.argv[0] 116 sys.exit() httplib代理方法: conn = httplib.HTTPConnection('120.28.64.69',8080) conn.request('GET',r'http://www.ip.cn/getip.php?action=getip') r = conn.getresponse() while 1: data = r.read(1024) print data if len(data)<1024: break socket代理方法: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('120.28.64.69', 8080)) s.send(r'GET http://www.ip.cn/getip.php?action=getip HTTP/1.1\r\nAccept: text/plain\r\n\r\n') data1 = '' while 1: data = s.recv(1024) print data if len(data) < 1024: break s.close() self.response.headers['content-type'] = 'text/html' self.response.out.write(data1) url='http://www.google.com' urllib.FancyURLopener(proxies={'http':'http://120.28.64.69:8080'}).open(url).read()   1 # -*- coding:utf-8 -*-   2 # http代理服务器   3 # 1.ip限制,mac限制   4 #   5 # socketref@hotmail.com   6 # www.sw2us.com   7   8 "exec" "python" "-O" "$0" "$@"   9 10 __doc__ = """sw2us HTTP Proxy. 11 12 """ 13 14 __version__ = "0.2.1" 15 16 import BaseHTTPServer, select, socket, SocketServer, urlparse 17 import httplib,traceback,re 18 import os,sys,re,mimetools,zlib,StringIO,gzip,time,StringIO 19 20 21 class ConfigProperty: 22    def __init__(self,owner): 23        self.key='' 24        self.value='' 25    26    def create(self,text): 27        #text -  key=value 28        #@return: boolean 29        pos = text.find('#') 30        if(pos !=-1): 31            text = text[:pos] 32        pair = text.split('=') 33        if len(pair) !=2: 34            #print "Property Line Invalid:%s"%(text) 35            return False 36        k = pair[0].strip() 37        v = pair[1].strip() 38        self.key = k 39        self.value = v 40 41        return True 42    43    def toString(self): 44        s ='' 45        try:            46            s = "%s=%s"%(self.key,self.value)            47        except: 48            return '' 49        return s 50    51    def toInt(self): 52        r=0 53        try: 54            r = int(self.value) 55        except: 56            r =0 57        return r 58    59    def toFloat(self): 60        r=0.0 61        try: 62            r = float(self.value) 63        except: 64            r=0.0 65        return r 66    67    68 #@def SimpleConfig 69 # 简单配置信息文件,基本格式 : key=value 70 class SimpleConfig: 71    def __init__(self): 72        self._file='' 73        self._props=[] 74        self._strip = True 75        76    def open(self,file,strip=True): 77        #打开配置文件 78        #@param strip - 是否裁剪不可见首尾两端的字符 79        try: 80            self._strip = strip 81            self._props=[] 82            fh = open(file,'r') 83            lines = fh.readlines()            84            for text in lines:                85                prop = ConfigProperty(self) 86                if prop.create(text) == False:                    87                    prop = None 88                else:                    89                    self._props.append(prop)                    90            fh.close() 91        except:            92            return False 93        return True 94 95    def toString(self): 96        s='' 97        for p in self._props: 98            s = s + p.toString() +"\n" 99        return s 100    101    def saveAs(self,file): 102        #保存配置信息到文件 103        try: 104            fh = open(file,'w') 105            fh.write(toString()) 106            fh.close() 107        except: 108            print "write File Failed!" 109            return False 110        return True 111    112    def getProperty(self,name): 113        #取属性值 114        prop=None 115        try: 116            for p in self._props: 117                if p.key == name: 118                    prop = p 119                    break 120        except: 121            pass 122        123        return prop 124    125    def getPropertyValue(self,key,default=''): 126        prop = self.getProperty(key) 127        if not prop: 128            return default 129        return prop.value 130    131    def getPropertyValueAsInt(self,name,default=0): 132        prop = self.getPropertyValue(name) 133        134        if not prop: 135            return default 136        r=default 137        try: 138            r = int(prop) 139        except:pass 140        return r 141    142    def getPropertyValueAsFloat(self,name,default=0.0): 143        prop = self.getPropertyValue(name) 144        if not prop: 145            return default 146        r = default 147        try: 148            r = float(r) 149        except:pass 150        return r 151    152 153 #===========================================# 154 155    156 #===========================================#

1,265

社区成员

发帖
与我相关
我的任务
社区描述
软件工程/管理 管理版
社区管理员
  • 研发管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧