實現多執行緒埠掃瞄

2021-10-03 08:34:00 字數 2141 閱讀 8580

實驗要求

能至少掃瞄5個ip位址;

針對每個ip位址,開設100個執行緒同時對其進行掃瞄;

如果埠開啟,使用函式getservbyport獲取其服務名,在螢幕上列印:ip port servername,如果是未知服務,則螢幕顯示:ip port unkonown

實驗環境

red hat 9

**threadsportscan.c

#include

#include

#include

#include

#include

#include

#include

#include

void

print_usage

(char

* str)

typedef

struct portinfoport;

intscanone

(struct sockaddr_in scanip)

int ret =

connect

(sockfd,

(struct sockaddr*

)&scanip,

sizeof

(scanip));

if(ret <0)

else

}else

if(ret ==0)

return-1

;}void

*scanport

(void

* arg)

else

if(ret ==0)

continue

;else

}return;}

intmain

(int argc,

char

**ar**)

int i;

for(i=

0; i

3; i++

)inet_aton

(ar**[i+1]

,&scanip[i]);

min_port =

atoi

(ar**[i+1]

);max_port =

atoi

(ar**[i+2]

);thread_num =

100;

//thread_num = atoi(ar**[i+3]);

//if(max_port - min_port < thread_num)

//thread_num = max_port - min_port;

int len =

(max_port - min_port)

/ thread_num;

if(max_port % thread_num !=

0)

len++;if

((thread =

(pthread_t*

)malloc

(sizeof

(pthread_t)

* thread_num * i))==

null

)printf

("malloc thread error");

printf

("\naddress\t\t\tport\t\tstatus\t\tprotocal\n");

int j, k;

for(j =

0; j < i; j++

)//pthread_join(thread[k+j*thread_num], null);

}for

(k=0

; k)pthread_join

(thread[k+j*thread_num]

,null);

}if(thread !=

null

)free

(thread)

;return0;

}

執行結果

由於沒有太多的主機,因此只掃瞄了虛擬機器和物理機兩個ip位址。輸入的命令表示目標主機ip(乙個或多個,本程式設定最大個數為5個)、起始埠號、結束埠號,每個ip都會在這埠號範圍內進行掃瞄。,且為100個並行執行緒。

多執行緒埠掃瞄程式

實現乙個多執行緒埠掃瞄程式 要求 1 能至少掃瞄5個ip位址 2 針對每個ip位址,開設100個執行緒同時對其進行掃瞄 3 如果埠開啟,使用函式getservbyport獲取其服務名,在螢幕上列印 ip port servername,如果是未知服務,則螢幕顯示 ip port unkonown 注...

python埠掃瞄器(多執行緒)

我們這裡拿某特爾的一款九代i5cpu做例子,這一款是6執行緒的。而這一款,是某特爾的九代i9 各位大佬,可以看出來執行緒的差別有多大了吧,執行緒就是決定了運算速度,所以說啊,有執行緒和沒執行緒的差距有多大哈 廢話說完,讓我們正式進入 coding utf 8 import socket,time,t...

基於C 實現的多執行緒埠掃瞄器

1 概述 1.1 課程設計目的 加深tcp ip協議的理解,掌握tcp四次握手機制,同時熟悉socket程式設計。1.2 課程設計內容 實現乙個埠掃瞄器 支援多程序 執行緒 能對單個指定主機進行掃瞄或掃瞄指定網段內的主機 能掃瞄特定的部分埠或對指定的埠段內的埠進行逐個掃瞄 能夠顯示所開放埠的服務名稱...