2014-01-19 05:16:24 +00:00
|
|
|
import socket, struct
|
2012-06-26 08:49:34 +00:00
|
|
|
|
|
|
|
# Python socket module does not have this constant
|
|
|
|
SO_ORIGINAL_DST = 80
|
|
|
|
|
|
|
|
class Resolver:
|
|
|
|
def original_addr(self, csock):
|
|
|
|
odestdata = csock.getsockopt(socket.SOL_IP, SO_ORIGINAL_DST, 16)
|
|
|
|
_, port, a1, a2, a3, a4 = struct.unpack("!HHBBBBxxxxxxxx", odestdata)
|
|
|
|
address = "%d.%d.%d.%d" % (a1, a2, a3, a4)
|
|
|
|
return address, port
|