aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/platform/lsof.py
diff options
context:
space:
mode:
authorIvaylo Popov <popov.ivo@gmail.com>2013-05-27 23:09:42 -0400
committerIvaylo Popov <popov.ivo@gmail.com>2013-05-27 23:09:42 -0400
commitffeede9b39c8d269766fd56d02eb7e78d8d13bb2 (patch)
tree31fe56a11080900d712e647ad4a48d392b7e3d68 /libmproxy/platform/lsof.py
parent82cb1dae41d4211832c28f65f45196e8b648ee65 (diff)
downloadmitmproxy-ffeede9b39c8d269766fd56d02eb7e78d8d13bb2.tar.gz
mitmproxy-ffeede9b39c8d269766fd56d02eb7e78d8d13bb2.tar.bz2
mitmproxy-ffeede9b39c8d269766fd56d02eb7e78d8d13bb2.zip
Use lsof instead of pfctl to find target host on OSX in transparent mode.
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])