Pythonã§ãã±ãããã£ããã£
ã¨ããäºæ ã«ãããã±ãããã£ããã£ããããã°ã©ã ãå¿ è¦ã«ãªã£ãã®ã§ãææ £ããPythonã§æ¸ãã¦ã¿ãããã±ãããã£ããã£ãããããã®ã©ã¤ãã©ãªã¯pcapyããã£ããã£ãããã±ãããèªåã§è§£æããã¨ã¤ããã®ã§ãimpacketã使ç¨ãããç¹ã«å¾è ã¯æ¥æ¬èªã®æ å ±ããã¾ããªãã®ã§æªæ¥ã®èªåã®ããã®ã¡ã¢æ¸ãã
å¿ è¦ãªã½ãã
Python2.5ï¼pcapyã®é¢ä¿ã§ãã¼ã¸ã§ã³ã¯2.5ã
WinPcap4.0ï¼pcapyã®é¢ä¿ã§ãã¼ã¸ã§ã³ã¯4.0ã
pcapy0.10.5ï¼WinPcapãpythonãã使ãããã®ã©ã¤ãã©ãªã
Impacket0.9.6ï¼ãã±ããã解æããããã®ã©ã¤ãã©ãªã
ãµã³ãã«ã½ã¼ã¹
# coding: shift_jis #---------------------------------------------------- import pcapy from impacket.ImpactDecoder import * #---------------------------------------------------- # ãã±ãããå±ãã¨å¼ã°ãã def f(header, data): eth = EthDecoder().decode(data) ip = eth.child() tcp = ip.child() src = (ip.get_ip_src(), tcp.get_th_sport()) dst = (ip.get_ip_dst(), tcp.get_th_dport()) data = tcp.get_data_as_string() print src, dst print data #---------------------------------------------------- #---------------------------------------------------- def main(): no = 1 # é©å½ã«æå¹ãªããã¤ã¹çªå·ãå ¥ãã dev = pcapy.findalldevs()[no] p = pcapy.open_live(dev, 65536, False, 100) p.setfilter("tcp") p.loop(-1, f) #----------------------------------------------------