我正在使用scapy嘗試列出在我的網絡上發送的所有http主機頭。我目前擁有的代碼是這樣的:OS X Scapy混雜模式
#!/usr/bin/env python
import sys
sys.path.append("/usr/local/lib/python2.7/site-packages")
import re
from scapy.all import *
import os
import urllib
conf.sniff_promisc=True
HOST_REGEX = "(?<=\r\nHost\:)([A-Za-z\.]){4,40}(?=\r\n)"
def print_host_header(pckt):
if pckt:
raw = pckt.getlayer(Raw)
if raw:
raw_pckt_data = raw.load
host_results = re.search(HOST_REGEX, raw_pckt_data)
if host_results:
print "[*] Request to: "+str(host_results.group(0))
if __name__ == "__main__":
if os.getuid()!=0:
print "[!] Not running as root."
exit(1)
sniff(filter='tcp', prn=print_host_header, store=0)
這個作品非常好(這顯然不能讀取的被加密的SSL/TLS流量),但我似乎並沒有將無法從我的筆記本電腦獲取任何數據包(這是運行腳本的計算機)。我設置conf.promisc
爲真,並根據使用ifconfig我在混雜模式:
735Tesla # ifconfig en1
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
ether 60:c5[...]
inet6 fe80::62c5:47ff:fe8b:3768%en1 prefixlen 64 scopeid 0x5
inet 192.168.1.8 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=1<PERFORMNUD>
media: autoselect
status: active
735Tesla #
難道還有其他原因,我將無法捕捉到去往其他計算機的包?
我運行OS X 10.9.1(我真的應該更新或補丁轉到失敗,我想:P)
你是怎麼解決的? – Teo