日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux编写一个简单的端口扫描程序,小弟我在linux下写了个简单的多线程端口扫描程序,运行时出现有关问题,请问一下(2)...

發布時間:2023/12/2 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux编写一个简单的端口扫描程序,小弟我在linux下写了个简单的多线程端口扫描程序,运行时出现有关问题,请问一下(2)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

當前位置:我的異常網? Linux/Unix???小弟我在linux下寫了個簡單的多線程端口掃描程序,

小弟我在linux下寫了個簡單的多線程端口掃描程序,運行時出現有關問題,請問一下(2)

www.myexceptions.net??網友分享于:2013-02-26??瀏覽:23次

usleep(1000);

printf( "\nThread ? ending....\n ");

while(g_nThreadNum> 0)

{

usleep(1);

printf( " ? =|=\t%d ? threads ? \r ",g_nThreadNum);

}

printf( "threadnum ? = ? %d ", ? g_nThreadNum);

printf( "\nThread ? ended!\n ");

}

int ? main(int ? argc, ? char ? **argv)

{

int ? i, ? j, ? nStartPort, ? nEndPort,nThread, ? ret, ? index;

int ? nPort[1000];

pthread_t ? tid;

/* ? 當前的線程數量 ? */

g_nThreadNum ? = ? 0;

host ? = ? argv[1];

nThread ? = ? atoi(argv[3]);

sscanf(argv[2], ? "%d-%d ", ? &nStartPort, ? &nEndPort);

printf( "nStartPort ? = ? %d\n ", ? nStartPort);

printf( "nEndPort ? = ? %d\n ", ? nEndPort);

/* ? 最大線程數 ? */

g_nMaxThread ? = ? (nThread ? > = ? 1000)? ? 1000 ? : ? nThread;

timeout.tv_usec ? = ? 0;

if ? (g_nMaxThread ? > ? 500)

timeout.tv_sec ? = ? 2;

else

timeout.tv_sec ? = ? 1;

printf( "MaxThread ? = ? %d\n ", ? g_nMaxThread);

printf( "ThreadNum ? = ? %d\n ", ? g_nThreadNum);

index ? = ? 0;

for ? (i ? = ? nStartPort; ? i ? <= ? nEndPort; ? i++, ? index++)

nPort[index] ? = ? i;

for ? (j ? = ? 0; ? j ? < ? index; ? j++)

{

g_nThreadNum++;

/* ? 若超過最大的線程數,程序休眠等待線程的釋放 ? */

while ? (g_nThreadNum ? > = ? g_nMaxThread)

{

usleep(10);

}

ret ? = ? pthread_create(&tid, ? NULL, ? (void ? *)thread_scan_port, ? &nPort[j]);

if ? (0 ? != ? ret)

{

perror( "\npthread_create ");

exit(1);

}

}

//printf( "ThreadNum ? = ? %d\n ", ? g_nThreadNum);

WaitThreadEnd();

return ? 0;

}

編譯: ? gcc ? -lpthread ? PortScanner.c ? -o ? PortScanner

運行:./PortScanner ? 192.168.2.1 ? 1-1000 ? 500

注:192.168.2.1 ? 要掃描的地址 ? 1-1000 ? 端口范圍 ? 500 ? 指定可以產生的最大線程數

當端口和線程比較大時運行就出問題了

------解決方案--------------------

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define MAX_PORT 4000

#define MAX_THREAD 100

/* basename(argv[0]). netBSD,linux and gnu libc all define it. */

extern char *__progname;

/* globals */

int port_num,thread_num=100;

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

int main(int argc,char **argv)

{

void *thread_main(void *);

pthread_t tid;

#ifndef HAVE__PROGNAME

__progname = argv[0];

#endif

printf( "----kf_701 scan tool--------- ");

文章評論

總結

以上是生活随笔為你收集整理的linux编写一个简单的端口扫描程序,小弟我在linux下写了个简单的多线程端口扫描程序,运行时出现有关问题,请问一下(2)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。