fix bug in pcap
This commit is contained in:
parent
97f3441e58
commit
b221cb4f47
|
@ -32,9 +32,6 @@ PCAP_SNAPLEN = 2048
|
||||||
LINKTYPE_ETHERNET = 1
|
LINKTYPE_ETHERNET = 1
|
||||||
|
|
||||||
async def do_pcap(devname="wlp2s0", pcapname="capture.pcap"):
|
async def do_pcap(devname="wlp2s0", pcapname="capture.pcap"):
|
||||||
if isinstance(devname, str):
|
|
||||||
devname = devname.encode()
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
if not isinstance(loop, asyncio.selector_events.BaseSelectorEventLoop):
|
if not isinstance(loop, asyncio.selector_events.BaseSelectorEventLoop):
|
||||||
raise Exception("you gotta run it on linux")
|
raise Exception("you gotta run it on linux")
|
||||||
|
@ -44,11 +41,13 @@ async def do_pcap(devname="wlp2s0", pcapname="capture.pcap"):
|
||||||
sock = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_IP))
|
sock = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_IP))
|
||||||
sock.setblocking(False)
|
sock.setblocking(False)
|
||||||
|
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, devname)
|
# sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, devname)
|
||||||
|
# NO htons on this call
|
||||||
|
sock.bind((devname, ETH_P_IP))
|
||||||
|
|
||||||
logger.info("setting promisc mode")
|
logger.info("setting promisc mode")
|
||||||
ifr = ifreq()
|
ifr = ifreq()
|
||||||
ifr.ifr_ifrn = devname
|
ifr.ifr_ifrn = devname.encode()
|
||||||
fcntl.ioctl(sock.fileno(), SIOCGIFFLAGS, ifr)
|
fcntl.ioctl(sock.fileno(), SIOCGIFFLAGS, ifr)
|
||||||
ifr.ifr_flags |= IFF_PROMISC
|
ifr.ifr_flags |= IFF_PROMISC
|
||||||
fcntl.ioctl(sock.fileno(), SIOCSIFFLAGS, ifr)
|
fcntl.ioctl(sock.fileno(), SIOCSIFFLAGS, ifr)
|
||||||
|
|
Loading…
Reference in New Issue