-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinpcap-sendrecv.py
More file actions
38 lines (30 loc) · 1.21 KB
/
winpcap-sendrecv.py
File metadata and controls
38 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import codecs
import stack.winpcapyif
import stack.utils
import stack.process
winp = stack.winpcapyif.bringupwinpcapy("Microsoft", recv=True)
mymac = [int(x) for x in codecs.decode(bytearray("34f39a8e2966",'utf-8'),'hex')]
while True:
p = stack.winpcapyif.readwinpcapyethpacket(winp,dump=False)
if not stack.eth.dstfilter(mymac,p,asbytes=True):
continue
stack.utils.hexdump(p)
info, out = stack.process.processEth(p,processIP=stack.process.processIP,processARP=stack.process.processARP)
print('\n'.join(info))
print("==============")
exit()
arp_request_hex_template = "%(dst_mac)s%(src_mac)s08060001080006040001" \
"%(sender_mac)s%(sender_ip)s%(target_mac)s%(target_ip)s" + "00" * 18
packet = bytearray(arp_request_hex_template % {
"dst_mac": "68c44da8f91a",
"src_mac": "34f39a8e2966",
"sender_mac": "34f39a8e2966",
"target_mac": "68c44da8f91a",
# 192.168.0.1
"sender_ip": "c0a82b11",
# 192.168.0.2
"target_ip": "c0a82b01"
} ,'utf-8')
# Send the packet (ethernet frame with an arp request) on the interface
stack.winpcapyif.writewinpcapyethpacket(winp, codecs.decode(packet,'hex'),dump=True)