aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/platform/lsof.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2013-06-08 16:28:47 -0700
committerAldo Cortesi <aldo@corte.si>2013-06-08 16:28:47 -0700
commitd3beaa738223947390bc66cdb649bf3cbaba6c28 (patch)
tree217e7f292564bbd168b8a2e69b90d85124729197 /libmproxy/platform/lsof.py
parent1a5c27aa7db69f6175a8bb493fde85a8e92dcff7 (diff)
parentffeede9b39c8d269766fd56d02eb7e78d8d13bb2 (diff)
downloadmitmproxy-d3beaa738223947390bc66cdb649bf3cbaba6c28.tar.gz
mitmproxy-d3beaa738223947390bc66cdb649bf3cbaba6c28.tar.bz2
mitmproxy-d3beaa738223947390bc66cdb649bf3cbaba6c28.zip
Merge pull request #132 from ipopov/master
A humble pull request
Diffstat (limited to 'libmproxy/platform/lsof.py')
-rw-r--r--libmproxy/platform/lsof.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/libmproxy/platform/lsof.py b/libmproxy/platform/lsof.py
new file mode 100644
index 00000000..25c0e33f
--- /dev/null
+++ b/libmproxy/platform/lsof.py
@@ -0,0 +1,17 @@
+import re
+
+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" in i and spec in i:
+ m = re.match(".* (\S*)->%s" % spec, i)
+ if m:
+ s = m.group(1).split(":")
+ if len(s) == 2:
+ return s[0], int(s[1])