mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-12-04 19:46:44 +00:00
Merge pull request #300 from zbrdge/freebsd-platform
Freebsd 10 platform
This commit is contained in:
commit
b0c366aa45
@ -7,3 +7,6 @@ if sys.platform == "linux2":
|
||||
elif sys.platform == "darwin":
|
||||
import osx
|
||||
resolver = osx.Resolver
|
||||
elif sys.platform == "freebsd10":
|
||||
import osx
|
||||
resolver = osx.Resolver
|
||||
|
@ -7,6 +7,10 @@ import pf
|
||||
structures returned, and compiling userspace tools to test and work with
|
||||
this turns out to be a pain in the ass. Parsing pfctl output is short,
|
||||
simple, and works.
|
||||
|
||||
Note: Also Tested with FreeBSD 10 pkgng Python 2.7.x.
|
||||
Should work almost exactly as on Mac OS X and except with some changes to
|
||||
the output processing of pfctl (see pf.py).
|
||||
"""
|
||||
|
||||
class Resolver:
|
||||
|
@ -1,3 +1,4 @@
|
||||
import sys
|
||||
|
||||
def lookup(address, port, s):
|
||||
"""
|
||||
@ -11,6 +12,11 @@ def lookup(address, port, s):
|
||||
if "ESTABLISHED:ESTABLISHED" in i and spec in i:
|
||||
s = i.split()
|
||||
if len(s) > 4:
|
||||
s = s[4].split(":")
|
||||
if sys.platform == "freebsd10":
|
||||
# strip parentheses for FreeBSD pfctl
|
||||
s = s[3][1:-1].split(":")
|
||||
else:
|
||||
s = s[4].split(":")
|
||||
|
||||
if len(s) == 2:
|
||||
return s[0], int(s[1])
|
||||
|
4
test/data/pf02
Normal file
4
test/data/pf02
Normal file
@ -0,0 +1,4 @@
|
||||
No ALTQ support in kernel
|
||||
ALTQ related functions disabled
|
||||
all tcp 127.0.0.1:8080 (5.5.5.6:80) <- 192.168.1.111:40001 FIN_WAIT_2:FIN_WAIT_2
|
||||
all tcp 127.0.0.1:8080 (5.5.5.5:80) <- 192.168.1.111:40000 ESTABLISHED:ESTABLISHED
|
@ -1,13 +1,15 @@
|
||||
import tutils
|
||||
import tutils, sys
|
||||
from libmproxy.platform import pf
|
||||
|
||||
|
||||
class TestLookup:
|
||||
def test_simple(self):
|
||||
p = tutils.test_data.path("data/pf01")
|
||||
d = open(p,"rb").read()
|
||||
if sys.platform == "freebsd10":
|
||||
p = tutils.test_data.path("data/pf02")
|
||||
d = open(p,"rb").read()
|
||||
else:
|
||||
p = tutils.test_data.path("data/pf01")
|
||||
d = open(p,"rb").read()
|
||||
assert pf.lookup("192.168.1.111", 40000, d) == ("5.5.5.5", 80)
|
||||
assert not pf.lookup("192.168.1.112", 40000, d)
|
||||
assert not pf.lookup("192.168.1.111", 40001, d)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user