歡迎您光臨本站 註冊首頁

python2.7使用scapy發送syn實例

←手機掃碼閱讀     niceskyabc @ 2020-05-06 , reply:0

我就廢話不多說了,大家看代碼吧!
from scapy.all import * def syn(): scrIP = '192.168.10.29' srcPort = 23345 desIP = '12.39.27.23' desPort = 8000 ip = IP(src=scrIP, dst=desIP) tcp = TCP(sport=srcPort, dport=desPort, seq=13131342, flags='S') pkg = ip/tcp # c->s syn res = sr1(pkg) res.display()
補充知識:用python 通過ip獲取mac和網卡類型(同一網段)
通過網上查閱目前找到的幾種方式
環境使用window和linux系統
使用nmap,python-nmap需要依賴機器安裝nmap工具
import nmap nm=nmap.PortScanner() nm.scan('xxx.xxx.xxx.xxx','xx') # ip地址和端口,端口不填也可以 a=nm['xxx.xxx.xxx.xxx'] #返回主機的詳細信息 print(a) ################################## {'status': {'state': 'up', 'reason': 'arp-response'}, 'hostnames': [{'type': 'PTR', 'name': 'bogon'}], 'vendor': {'00:0C:29:F6:2B:F0': 'VMware'}, 'addresses': {'mac': '00:0C:29:F6:2B:F0', 'ipv4': 'xxx.xxx.xxx.xxx'}, 'tcp': {111: {'product': 'Microsoft Windows 7 - 10 microsoft-ds', 'state': 'open', 'version': '', 'name': 'microsoft-ds', 'conf': '10', 'extrainfo': 'workgroup: WORKGROUP', 'reason': 'syn-ack', 'cpe': 'cpe:/o:microsoft:windows'}}}
這種方式獲取非常簡單,但是會耗費很大的時間,不建議使用
通過控制檯命令arp -a
def output_cmd(command): r = os.popen(command) content = r.read() r.close() return content def arp_command(ip_address): ping_cmd = "ping " + ip_address + " -n 2 " result = output_cmd(ping_cmd) find_ttl = result.find("TTL") if find_ttl != -1: arp_cmd = "arp -a %s" % ip_address arp_result = output_cmd(arp_cmd) ip2 = ip_address + " [ ]+([w-]+)" ip2_mac = re.findall(ip2, arp_result) if len(ip2_mac): return ip2_mac[0] else: return 0 else: result = u'無人使用的ip' return result
這個是通過先ping,之後在arp -a ip 來獲取mac地址,這種方式需要拿到數據後自行去通過正則匹配mac地址,演示的為window上的匹配,linux需要自行修改匹配規則
通過scapy模塊(必須機器ipv6未被禁止)
from scapy.all import * arp_pkt = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip) res = srp1(arp_pkt, timeout=1, verbose=0) print {"localIP": res.psrc, "mac": res.hwsrc}
通過arpreq模塊
[root@oradb ~]# python Python 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import arpreq >>> arpreq.arpreq('192.168.xx.xxx') 'xx:xx:xx:xx:xx:xx'
通過上述方法獲取mac地址之後獲取網卡類型
可以直接使用mac.py
pip install mac.py
from macpy import Mac mac = Mac() information = mac.search(00-11-F1-01-01) print information
如果感覺信息還是有點老的話,需要自己手動去IEEE上面下載mac和網卡廠商的比對文件自行比對就行了


[niceskyabc ] python2.7使用scapy發送syn實例已經有314次圍觀

http://coctec.com/docs/python/shhow-post-233056.html