下面是我在windows上做的測試版,用的是線程。我覺得用nc測試比較好,直接用netstat-an | Findstr/I " UDP " | Findstr " 22 "比較好,因為22口太特殊了,很容易被抓到。另外,nc判斷端口的常規方式是看提示信息。
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
# include & lttchar.h & gt
# include & ltwindows.h & gt
# include & ltprocess.h & gt
UINT _ _ stdcall thread func(LPVOID lpParam){
//使用黑客字符串作為nc提交的數據。
int ret = system("回聲黑客| nc.exe-u 127.1 22 ");
//ret==0表示端口22沒有打開。
if (ret == 0 ) printf("nc:寫錯誤:連接被拒絕。\ n ");
返回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 ");
返回0;
}
歡迎來到X 30貼吧,壹個高質量的計算機技術交流平臺。