最近忙着熟悉导师的研究方向和OPNET网络仿真工具,做毕设翻译那会找导师要过几篇英文文献,认真翻译了 Enable Pervasive Healthcare through Continuous Remote Health Monitoring 一文,论文前半部分概述了远程医疗监控(RHM)的体系架构,后半部分介绍了ViiCare产品提供的解决方案。概述性的东西毕竟只是起个引导作用,而且短短几页的论文也不可能会交待较多的细节。如果要结合OPNET来分析网络性能什么的显然是不知从何下手,于是乎习惯性的Google了一番,找到了一篇博士论文,正准备下载的时候… 乖乖,现在已经不是校园网了哟,立马向西电的基友求助,短信刚发出去就想到了个令人激动的消息——隐约记得交大网络信息中心是提供校外访问的代理服务器的,那么?Google一下立马找到了这个链接,网页中提供了局域网和ADSL下的使用方法,都是针对IE的。说白了就是提供了代理服务器的地址和端口号,如果只是在浏览器中使用的话SwitchySharp/Foxyproxy插件新增个代理就好了,试了下速度很理想!
代理服务器
代理服务器名:inproxy.sjtu.edu.cn
端口号:8000 OR 80
连通后会让输入jAccount帐号密码,这个新生已经可以申请了,perfect!
全局代理
虽然大部分情况在浏览器中使用代理就足够了,但有时其他应用程序也许也需要代理访问,这个时候就稍微有点麻烦喽。 如果想要全局代理的话则需要模拟http认证,Windows下似乎有p-roxycap比较方便,Linux下暂时还没看到类似的软件,之前也没怎么需要用非浏览器应用中使用代理,这方面了解不太多。舍友yqt用Python写了个DXTL的全局代理,于是乎便借过来用了下,还不错,效果就是下边这个样子:
需要使用时只需在Terminal下运行python sjtu-inproxy.py
即可,很方便。
上代码==>
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Filename: sjtu-inproxy.py
'''
*major code is retrieved and modified from webvpn_proxy_via_stunnel.py by
yqt.
http://script-holic.appspot.com/2013/04/22/SPDY%20proxy%E2%86%92HTTP%E4%BB%A3%E7%90%86/%E5%85%A8%E5%B1%80%E4%BB%A3%E7%90%86
'''
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from httplib import HTTPResponse
from SocketServer import ThreadingMixIn
import socket, os, select
import threading
import base64
# Minimize Memory Usage
threading.stack_size(128*1024)
BufferSize = 8192
# local proxy
local_proxy_host = '' # bind all network types
local_proxy_port = 8090
# proxy host
proxy_host = 'inproxy.sjtu.edu.cn'
proxy_port = 80
proxy_user = 'your jAccount user name'
proxy_pass = 'your jAccount user secret'
auth = proxy_user + ':' + proxy_pass
class Handler(BaseHTTPRequestHandler):
remote = None
# Ignore Connection Failure
def handle(self):
try:
BaseHTTPRequestHandler.handle(self)
except socket.error: pass
def finish(self):
try:
BaseHTTPRequestHandler.finish(self)
except socket.error: pass
# CONNECT Data Transfer
def transfer(self, a, b):
fdset = [a, b]
while True:
r,w,e = select.select(fdset, [], [])
if a in r:
data = a.recv(BufferSize)
if not data: break
b.sendall(data)
if b in r:
data = b.recv(BufferSize)
if not data: break
a.sendall(data)
def proxy(self):
if self.remote is None or self.lastHost != self.headers['Host']:
self.remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.remote.connect((proxy_host, proxy_port))
self.remote.sendall(self.requestline.encode('ascii') + b'\r\n')
# Add auth inf.
self.headers['Proxy-Authorization'] = 'Basic %s' % base64.b64encode(auth)
#self.remote.sendall('Proxy-Authorization: Basic %s\r\n' % base64.b64encode(auth))
headerstr = str(self.headers).replace('\r\n', '\n').replace('\n', '\r\n')
self.remote.sendall(headerstr.encode('ascii') + b"\r\n")
# Send Post data
if self.command == 'POST':
self.remote.sendall(self.rfile.read(int(self.headers['Content-Length'])))
response = HTTPResponse(self.remote, method=self.command)
response.begin()
# Reply to the browser
status = 'HTTP/1.1 ' + str(response.status) + ' ' + response.reason
self.wfile.write(status.encode('ascii') + b'\r\n')
hlist = []
for line in response.msg.headers: # Fixed multiple values of a same name
if 'TRANSFER-ENCODING' not in line.upper():
hlist.append(line)
self.wfile.write(''.join(hlist) + b'\r\n')
if self.command == 'CONNECT' and response.status == 200:
return self.transfer(self.remote, self.connection)
else:
while True:
response_data = response.read(BufferSize)
if not response_data: break
self.wfile.write(response_data)
do_POST = do_GET = do_CONNECT = proxy
class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
#address_family = socket.AF_INET6 # IPV6
address_family = socket.AF_INET # IPV4
server_address = (local_proxy_host, local_proxy_port)
server = ThreadingHTTPServer(server_address, Handler)
print('Proxy over {}:{}\nPlease set your browser\'s or PAC\'s proxy to {}'.format(proxy_host, proxy_port, server_address))
try:
server.serve_forever()
except:
os._exit(1)