-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple_proxy.py
47 lines (39 loc) · 1.41 KB
/
simple_proxy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import re
import asyncore
from barneymc.protocol.packet import *
from barneymc.net import proxy
class SimpleTunnel(proxy.ClientHandler):
def __init__(self, *args, **custom_settings):
proxy.ClientHandler.__init__(self, *args, **custom_settings)
#Connect to the server
self.server_handler.connect2()
#Packet handlers
self.handlers = {
0x01: self.login,
0x02: self.handshake
}
#Just an example...
def handshake(self, p):
self.print_packet(p)
if p.direction == CLIENT_TO_SERVER:
m = re.match('^([A-Za-z0-9_]{1,16});(.*):(\d+)$', p.data['username_host'])
if m:
print "Username: %s" % m.group(1)
print "Host: %s" % m.group(2)
print "Port: %d" % int(m.group(3))
return True #Return true to pass it on to relay this packet (rather than consuming it)
def login(self, p):
self.print_packet(p)
if p.direction == SERVER_TO_CLIENT:
print "Starting pass through..."
self.start_pass_through()
return True
def default_handler(self, p):
self.print_packet(p)
return True
if __name__ == '__main__':
p = proxy.Proxy(server_host = 'c.nerd.nu', server_port = 25565, player_handler = SimpleTunnel)
try:
asyncore.loop()
except KeyboardInterrupt:
p.close()