欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

歡迎來到夢飛科技

系統配置

當前優惠活動:

python措施挪用tcpdump舉辦闡明抓包過濾

之前在linux用python劇本寫一個抓包闡明小東西,實在不想用什么libpcap、pypcap所以,簡樸來了個tcpdump加grep搞定。根基思路是別離起tcpdump和grep兩個歷程,歷程直接通過pipe互換數據,簡樸

#! /usr/bin/python
def tcpdump():
        import subprocess, fcntl, os
        # sudo tcpdump -i eth0 -n -s 0 -w - | grep -a -o -E "Host: .*|GET /.*"
        cmd1 = ['tcpdump', '-i', 'eth0', '-n','-B', '4096','-s', '0', '-w', '-']
        cmd2 = ['grep', '--line-buffered', '-a', '-o', '-E', 'Host: .*|GET /.*']
        p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE)
        p2 = subprocess.Popen(cmd2, stdout=subprocess.PIPE, stdin=p1.stdout)
        flags = fcntl.fcntl(p2.stdout.fileno(), fcntl.F_GETFL)
        fcntl.fcntl(p2.stdout.fileno(), fcntl.F_SETFL, (flags | os.O_NDELAY | os.O_NONBLOCK))
        return p2
def poll_tcpdump(proc):
        #print 'poll_tcpdump....'
        import select
        txt = None
        while True:
                # wait 1/10 second
                readReady, _, _ = select.select([proc.stdout.fileno()], [], [], 0.1)
                if not len(readReady):
                        break
                try:
                        for line in iter(proc.stdout.readline, ""):
                                if txt is None:
                                        txt = ''
                                txt += line
                except IOError:
                        print 'data empty...'
                        pass
                break
        return txt
proc = tcpdump()
while True:
        text = poll_tcpdump(proc)
        if text:
                print '>>>> ' + text

運行結果:

 

python法子調用tcpdump舉行闡發抓包過濾

 

個中值得留意tcpdump中'-B', '4096'這個參數,官方文檔貌似沒有明晰提及,可是它是你辦理丟包的要害處所之一,雖然尚有-s這個參數也得好好操作!其他的各人可以自由發揮!

夢飛科技 - 全球數據中心基礎服務領先供應商

Copyright © 2003-2019 MFISP.COM. 國外服務器租用 IDC公司 版權所有 ? 粵ICP備11019662號

主站蜘蛛池模板: 宁夏| 图们市| 镇巴县| 寿阳县| 呈贡县| 任丘市| 绥棱县| 彭阳县| 繁峙县| 阜康市| 南安市| 德州市| 昭觉县| 建瓯市| 高清| 中西区| 哈尔滨市| 肥东县| 辽源市| 类乌齐县| 东乡族自治县| 铜陵市| 广宁县| 皮山县| 馆陶县| 通许县| 板桥市| 汾阳市| 鄂州市| 凭祥市| 保亭| 博罗县| 南康市| 黎平县| 扶绥县| 潢川县| 平凉市| 泸水县| 防城港市| 宣化县| 青铜峡市|