udp端口掃描程序代碼.doc_第1頁(yè)
udp端口掃描程序代碼.doc_第2頁(yè)
udp端口掃描程序代碼.doc_第3頁(yè)
udp端口掃描程序代碼.doc_第4頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(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)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論