下面是我在windows上的弄的壹個測試版本,使用了線程,我感覺用nc來測試,不如直接 netstat -an | findstr /I "udp" | findstr "22" ,因為22端口太其特了,很容易抓出來. 另外nc判斷端口常規的作法就是 nc -vv ip port 看提示信息就好了.
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <windows.h>
#include <process.h>
UINT __stdcall ThreadFunc(LPVOID lpParam) {
//將hacker字符串做為nc提交的數據
int ret = system("echo hacker | nc.exe -u 127.1 22");
//ret==0說明沒有開啟22端口
if (ret == 0 ) printf("nc: Write error: Connection refused.\n");
return 0;
}
int main()
{
HANDLE hThread = (HANDLE)_beginthreadex(0, 0, ThreadFunc, 0, 0, 0);
//等待3秒鐘,說明22端口可用
WaitForSingleObject(hThread, 3000);
//結束測試線程
TerminateThread(hThread, 0);
//重新開啟NC連接22端口
system("nc.exe -vv -u 127.1 22");
return 0;
}
歡迎光臨0x30貼吧,壹個高質量的計算機技術交流平臺.