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

歡迎來(lái)到夢(mèng)飛科技

系統(tǒng)配置

當(dāng)前優(yōu)惠活動(dòng):

python措施挪用tcpdump舉辦闡明抓包過(guò)濾

之前在linux用python劇本寫(xiě)一個(gè)抓包闡明小東西,實(shí)在不想用什么libpcap、pypcap所以,簡(jiǎn)樸來(lái)了個(gè)tcpdump加grep搞定。根基思路是別離起tcpdump和grep兩個(gè)歷程,歷程直接通過(guò)pipe互換數(shù)據(jù),簡(jiǎn)樸

#! /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

運(yùn)行結(jié)果:

 

python法子調(diào)用tcpdump舉行闡發(fā)抓包過(guò)濾

 

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

夢(mèng)飛科技 - 全球數(shù)據(jù)中心基礎(chǔ)服務(wù)領(lǐng)先供應(yīng)商

Copyright © 2003-2019 MFISP.COM. 國(guó)外服務(wù)器租用 IDC公司 版權(quán)所有 ? 粵ICP備11019662號(hào)

主站蜘蛛池模板: 安福县| 珲春市| 白玉县| 浦江县| 屏东县| 新绛县| 荣昌县| 阳新县| 吉安市| 海南省| 滨州市| 濉溪县| 邵阳市| 杭锦后旗| 出国| 汕头市| 观塘区| 元阳县| 建德市| 涟源市| 靖宇县| 大英县| 长沙县| 中牟县| 贵南县| 岢岚县| 景德镇市| 揭阳市| 潮安县| 从化市| 如皋市| 新沂市| 博兴县| 兴隆县| 鄂托克旗| 犍为县| 黑河市| 金阳县| 吉安市| 留坝县| 崇仁县|