使用shell來(lái)發(fā)tcp包的方法
經(jīng)常用tcpdump抓包來(lái)倒騰和學(xué)習(xí),但怎么觸發(fā)tcp包呢?寫一個(gè)客戶端程序,然后朝server上發(fā)包,肯定可以,但還有更簡(jiǎn)單的方法:
exec 8<>/dev/tcp/10.100.70.139/19006 echo -e "stats" >&8
用tcpdump抓包的結(jié)果為:
xxxxxx$ sudo tcpdump -iany port 19006 -Xnlps0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:56:54.177781 IP 10.100.70.139.34209 > 10.100.70.139.19006: Flags [S], seq 2048518213, win 43690, options [mss 65495,sackOK,TS val 1173337789 ecr 0,nop,wscale 8], length 0
0x0000: 4500 003c 5ef8 4000 4006 39e6 0a64 468b E..<^.@.@.9..dF.
0x0010: 0a64 468b 85a1 4a3e 7a19 e845 0000 0000 .dF...J>z..E....
0x0020: a002 aaaa a20c 0000 0204 ffd7 0402 080a ................
0x0030: 45ef b6bd 0000 0000 0103 0308 0000 0000 E...............
0x0040: 0000 0000 0000 0000 0000 0000 ............
23:56:54.177794 IP 10.100.70.139.19006 > 10.100.70.139.34209: Flags [S.], seq 480321333, ack 2048518214, win 43690, options [mss 65495,sackOK,TS val 1173337789 ecr 1173337789,nop,wscale 8], length 0
0x0000: 4500 003c 0000 4000 4006 98de 0a64 468b E..<..@.@....dF.
0x0010: 0a64 468b 4a3e 85a1 1ca1 1f35 7a19 e846 .dF.J>.....5z..F
0x0020: a012 aaaa a20c 0000 0204 ffd7 0402 080a ................
0x0030: 45ef b6bd 45ef b6bd 0103 0308 0000 0000 E...E...........
0x0040: 0000 0000 0000 0000 0000 0000 ............
23:56:54.177802 IP 10.100.70.139.34209 > 10.100.70.139.19006: Flags [.], ack 1, win 171, options [nop,nop,TS val 1173337789 ecr 1173337789], length 0
0x0000: 4500 0034 5ef9 4000 4006 39ed 0a64 468b E..4^.@.@.9..dF.
0x0010: 0a64 468b 85a1 4a3e 7a19 e846 1ca1 1f36 .dF...J>z..F...6
0x0020: 8010 00ab a204 0000 0101 080a 45ef b6bd ............E...
0x0030: 45ef b6bd 0000 0000 0000 0000 0000 0000 E...............
0x0040: 0000 0000 ....
23:57:05.744655 IP 10.100.70.139.34209 > 10.100.70.139.19006: Flags [P.], seq 1:7, ack 1, win 171, options [nop,nop,TS val 1173340681 ecr 1173337789], length 6
0x0000: 4500 003a 5efa 4000 4006 39e6 0a64 468b E..:^.@.@.9..dF.
0x0010: 0a64 468b 85a1 4a3e 7a19 e846 1ca1 1f36 .dF...J>z..F...6
0x0020: 8018 00ab a20a 0000 0101 080a 45ef c209 ............E...
0x0030: 45ef b6bd 6865 6c6c 6f0a 0000 0000 0000 E...hello.......
0x0040: 0000 0000 0000 0000 0000 ..........
23:57:05.744679 IP 10.100.70.139.19006 > 10.100.70.139.34209: Flags [.], ack 7, win 171, options [nop,nop,TS val 1173340681 ecr 1173340681], length 0
0x0000: 4500 0034 a98b 4000 4006 ef5a 0a64 468b E..4..@.@..Z.dF.
0x0010: 0a64 468b 4a3e 85a1 1ca1 1f36 7a19 e84c .dF.J>.....6z..L
0x0020: 8010 00ab a204 0000 0101 080a 45ef c209 ............E...
0x0030: 45ef c209 0000 0000 0000 0000 0000 0000 E...............
0x0040: 0000 0000 ....
23:57:05.744830 IP 10.100.70.139.19006 > 10.100.70.139.34209: Flags [F.], seq 1, ack 7, win 171, options [nop,nop,TS val 1173340681 ecr 1173340681], length 0
0x0000: 4500 0034 a98c 4000 4006 ef59 0a64 468b E..4..@.@..Y.dF.
0x0010: 0a64 468b 4a3e 85a1 1ca1 1f36 7a19 e84c .dF.J>.....6z..L
0x0020: 8011 00ab a204 0000 0101 080a 45ef c209 ............E...
0x0030: 45ef c209 0000 0000 0000 0000 0000 0000 E...............
0x0040: 0000 0000 ....
23:57:05.748555 IP 10.100.70.139.34209 > 10.100.70.139.19006: Flags [.], ack 2, win 171, options [nop,nop,TS val 1173340682 ecr 1173340681], length 0
0x0000: 4500 0034 5efb 4000 4006 39eb 0a64 468b E..4^.@.@.9..dF.
0x0010: 0a64 468b 85a1 4a3e 7a19 e84c 1ca1 1f37 .dF...J>z..L...7
0x0020: 8010 00ab a204 0000 0101 080a 45ef c20a ............E...
0x0030: 45ef c209 0000 0000 0000 0000 0000 0000 E...............
0x0040: 0000 0000 ....
真的是爽歪歪。 能用shell搞定的事, 絕不用C/C++.
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- Shell中exit和return的區(qū)別講解
- 在Shell腳本中調(diào)用另一個(gè)腳本的三種方式講解
- 使用shell腳本來(lái)給mysql加索引的方法
- 干掉一堆mysql數(shù)據(jù)庫(kù),僅需這樣一個(gè)shell腳本(推薦)
- linux shell之通過(guò)標(biāo)識(shí)測(cè)試文件系統(tǒng)屬性的方法示例
- linux shell中if的各種判斷
- linux shell之pushd、popd和dirs的使用講解
- linux shell之控制臺(tái)打印各種顏色字體和背景的實(shí)現(xiàn)方法
- shell腳本實(shí)現(xiàn)監(jiān)控某個(gè)進(jìn)程意外停止后拉起進(jìn)程
- 使用shell腳本每天對(duì)MySQL多個(gè)數(shù)據(jù)庫(kù)自動(dòng)備份的講解
相關(guān)文章
使用crontab每隔1分鐘執(zhí)行一個(gè)命令行腳本
這篇文章主要介紹了使用crontab每隔1分鐘執(zhí)行一個(gè)命令行腳本,文末介紹了crontab中如何設(shè)置每30秒執(zhí)行一次任務(wù),本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07
shell編程中for循環(huán)語(yǔ)句的實(shí)現(xiàn)過(guò)程及案例
Bash?Shell中主要提供了三種循環(huán)方式:for、while和until,下面這篇文章主要給大家介紹了關(guān)于shell編程中for循環(huán)語(yǔ)句的實(shí)現(xiàn)過(guò)程及案例,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04
linux shell腳本對(duì)未定義變量的判斷以及if的用法詳解
今天小編就為大家分享一篇linux shell腳本對(duì)未定義變量的判斷以及if的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
awk命令、awk編程語(yǔ)言詳細(xì)介紹和實(shí)例
這篇文章主要介紹了awk命令、awk編程語(yǔ)言詳細(xì)介紹和實(shí)例,講解了如awk中的記錄、域、分割符,awk的內(nèi)建變量和運(yùn)算符等,需要的朋友可以參考下2014-07-07
編寫shell腳本將VPS上的數(shù)據(jù)備份到Dropbox網(wǎng)盤的方法
這篇文章主要介紹了編寫shell腳本將VPS上的數(shù)據(jù)備份到Dropbox網(wǎng)盤的方法,注意Dropbox在國(guó)內(nèi)訪問(wèn)的網(wǎng)絡(luò)相關(guān)問(wèn)題,需要的朋友可以參考下2015-07-07

