diff options
author | Rouli <rouli.net@gmail.com> | 2013-01-17 17:33:29 +0200 |
---|---|---|
committer | Rouli <rouli.net@gmail.com> | 2013-01-17 17:33:29 +0200 |
commit | 446f9f0a0fc12159ba663d3b8bdc8f1206a197c7 (patch) | |
tree | 9cb474c3154fb4146cce41e40e25b4a8e3e57d46 /libmproxy/platform/pf.py | |
parent | 20fa6a30839500207d7d509fe3b8697dbd22a33e (diff) | |
parent | 280dd94198931bcd819848a70d68f6f5d9f3270b (diff) | |
download | mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.gz mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.bz2 mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'libmproxy/platform/pf.py')
-rw-r--r-- | libmproxy/platform/pf.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libmproxy/platform/pf.py b/libmproxy/platform/pf.py new file mode 100644 index 00000000..062d3311 --- /dev/null +++ b/libmproxy/platform/pf.py @@ -0,0 +1,16 @@ + +def lookup(address, port, s): + """ + Parse the pfctl state output s, to look up the destination host + matching the client (address, port). + + Returns an (address, port) tuple, or None. + """ + spec = "%s:%s"%(address, port) + for i in s.split("\n"): + if "ESTABLISHED:ESTABLISHED" in i and spec in i: + s = i.split() + if len(s) > 4: + s = s[4].split(":") + if len(s) == 2: + return s[0], int(s[1]) |