



下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、。/ udp.cpp :定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。/#include stdafx.h#include #include #pragma comment(lib, ws2_32.lib)#define MAXBUFF 8192#define ICMP_UNREACH_PORT 3#define ICMP_UNREACH 4enum CMD_NAME, DST_IP, START_PORT, LAST_PORT; structipunsigned int ip_v:4; /版本unsigned int ip_hl:4; /頭部長(zhǎng)unsigned char ip_tos; /服務(wù)類(lèi)型unsign
2、ed short ip_len; /總長(zhǎng)unsigned short ip_id; /鑒定域unsigned short ip_flags; /IP標(biāo)志unsigned short ip_off; /片偏移unsigned char ip_ttl; / TTLunsigned char ip_protocol; /協(xié)議unsigned short ip_sum; /頭部效驗(yàn)和structin_addrip_src, ip_dest; /源 ip 和目的 IP#define IP_RF 0x8000 /標(biāo)記收到數(shù)據(jù)#define IP_DF 0x4000#define IP_MF 0x2000#
3、define IP_OFFMASK 0x1fff;structicmpunsigned short inticmp_type;unsigned short inticmp_code;unsigned long inticmp_cksum;unsigned long inticmp_id;unsigned long inticmp_seq;unsigned short inticmp_data1;int main(intargc, char *argv) structtimevaltv;fd_setselect_fd;char buffMAXBUFF;intdstport, startport,
4、 endport;if (argc != 4) fprintf(stdout, usage: %s目的 ip 起始端口目的端口n, argvCMD_NAME);exit(EXIT_FAILURE);。1。WSADatawsaData;WSAStartup(MAKEWORD(2,2), &wsaData);structsockaddr_insend_sa;/ 發(fā)送端地址信息memset(&send_sa, 0, sizeof(send_sa);send_sa.sin_family = AF_INET;send_sa.sin_addr.s_addr = inet_addr(argvDST_IP);
5、startport = atoi(argvSTART_PORT);endport = atoi(argvLAST_PORT);SOCKET sock_send = socket(AF_INET, SOCK_DGRAM, 0);/ 發(fā)送用的描述符if (sock_send 0) perror( sock(SOCK_DGRAM);closesocket(sock_send);exit(EXIT_FAILURE);SOCKET sock_recv = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); /接收用的描述符if (sock_recv 0) perror( s
6、ocket(SOCK_RAW);closesocket(sock_recv);exit(EXIT_FAILURE);for (dstport = startport; dstport 0) structip *ip;structicmp *icmp;inthlen;int port;memset(&ip, 0, sizeof(ip);if (recvfrom(sock_recv, buff, MAXBUFF, 0, NULL, NULL) != 56)continue;ip = (structip *)buff;hlen = ip-ip_hlip_src.s_addr!=send_sa.sin_addr.s_addr)|(icmp-icmp_type!=ICMP_UNREACH)|(icmp-icmp_code != ICMP_UNREACH_PORT) | (port != dstport)continue;else structservent *se;se = getservbyport(htons(dstport), udp);if (se != NULL)printf(%5d %-20sn, dstport, (se = NULL) ? unknown: se-s_name);break;closesocket(sock_send
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 護(hù)理健康宣教平臺(tái)應(yīng)用
- 小班關(guān)于雨傘的課件
- 鄉(xiāng)鎮(zhèn)快遞合同范例
- 修井施工合同標(biāo)準(zhǔn)文本
- 書(shū)畫(huà)買(mǎi)賣(mài)合同標(biāo)準(zhǔn)文本
- 住院大夫護(hù)士合同標(biāo)準(zhǔn)文本
- 農(nóng)機(jī)租賃合同樣本簡(jiǎn)易
- 云閃付代理合同標(biāo)準(zhǔn)文本
- 買(mǎi)斷制合同標(biāo)準(zhǔn)文本
- 會(huì)計(jì)中介合作合同標(biāo)準(zhǔn)文本
- 截肢術(shù)后護(hù)理查房
- 安全工程專(zhuān)業(yè)英語(yǔ)術(shù)語(yǔ)
- 邊坡支護(hù)腳手架專(zhuān)項(xiàng)施工方案
- HG-T 6136-2022 非金屬化工設(shè)備 玄武巖纖維增強(qiáng)塑料貯罐
- 采供血相關(guān)標(biāo)準(zhǔn)
- 博碩全自動(dòng)層壓機(jī)
- 供應(yīng)商質(zhì)量事故索賠單
- 2023小學(xué)語(yǔ)文教師專(zhuān)業(yè)知識(shí)含部分答案(三套)
- 2023年河南省鄭州市中考一模語(yǔ)文試題(含答案與解析)
- 寶典三猿金錢(qián)錄
- 網(wǎng)頁(yè)制作技術(shù)知到章節(jié)答案智慧樹(shù)2023年通遼職業(yè)學(xué)院
評(píng)論
0/150
提交評(píng)論