IP scan |
答題得分者是:wu-eric
|
cashyy
高階會員 發表:117 回覆:322 積分:212 註冊:2004-04-30 發送簡訊給我 |
各位大大,小弟參考站內的文章,修改成下列程式碼,但不知是那裡有問題,會run非常久,小弟是想做成像ip scan一樣,可以搜尋同一網段的電腦!
AnsiString get,get1,get2,ret,aIP; int n,i; aIP = "192.168.1.3"; n = aIP.Pos("."); get = aIP.SubString(1,n-1); ret = get; aIP = aIP.SubString(n 1,aIP.Length()); n = aIP.Pos("."); get1 = aIP.SubString(1,n-1); ret = ret "." get1; aIP = aIP.SubString(n 1,aIP.Length()); n = aIP.Pos("."); get2 = aIP.SubString(1,n-1); ret = ret "." get2; WORD wVersionRequested=MAKEWORD(1,1); WSADATA wsaData; struct hostent *host; struct in_addr *myaddr; char ip_address[256]; TListItem *NewItem; ListView1->Items->Clear(); for(i=0;i<=255;i ) { ret = get "." get1 "." get2 "." IntToStr(i); WSAStartup(wVersionRequested, &wsaData); lstrcpy(ip_address, ret.c_str()); myaddr=(struct in_addr*)malloc(sizeof(struct in_addr)); myaddr->s_addr=inet_addr(ip_address); //小弟用debug的方式找到會停留很久的地方 host=gethostbyaddr((char *)myaddr, 4, AF_INET); if(host!=NULL) { NewItem=ListView1->Items->Add(); NewItem->Caption=host->h_name; ListView1->LargeImages = ImageList1; ListView1->Refresh(); } } free(myaddr); WSACleanup(); |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
|
cashyy
高階會員 發表:117 回覆:322 積分:212 註冊:2004-04-30 發送簡訊給我 |
引言: 那一行應該不是問題,IP的計算請參考下列站內網址: http://delphi.ktop.com.tw/topic.php?TOPIC_ID=68586 WSAStartup只要起始Winsock一次即可,不用放在迴圈裡,還有建議算出IP的數量後,分成不同的RANGE由THREAD去分別掃瞄,會快很多! ----------------------------------------------- Creation is the fundation of promotion.可以解釋一下這一行嗎?小弟不太懂!謝謝! |
wu-eric
中階會員 發表:14 回覆:82 積分:64 註冊:2004-03-17 發送簡訊給我 |
|
yhchu
一般會員 發表:2 回覆:70 積分:24 註冊:2004-01-28 發送簡訊給我 |
|
cashyy
高階會員 發表:117 回覆:322 積分:212 註冊:2004-04-30 發送簡訊給我 |
|
wu-eric
中階會員 發表:14 回覆:82 積分:64 註冊:2004-03-17 發送簡訊給我 |
這個範例,你參考看看
unit1.h 內容如下
#include "Func.h" //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; TListView *ListView1; TImageList *ImageList1; TEdit *Edit1; TEdit *Edit2; TLabel *Label1; TLabel *Label2; TComboBox *ComboBox1; void __fastcall Button1Click(TObject *Sender); void __fastcall ListView1DblClick(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); TLanComputerThread *LanComputerThread; };Unit1.cpp如下 AnsiString get,get1,get2,ret,aIP; int n,i,iThreadCount; aIP = ComboBox1->Text; n = aIP.Pos("."); get = aIP.SubString(1,n-1); ret = get; aIP = aIP.SubString(n 1,aIP.Length()); n = aIP.Pos("."); get1 = aIP.SubString(1,n-1); ret = ret "." get1; aIP = aIP.SubString(n 1,aIP.Length()); n = aIP.Pos("."); get2 = aIP.SubString(1,n-1); ret = ret "." get2; WORD wVersionRequested=MAKEWORD(1,1); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); struct hostent host[256]; struct hostent *tmpHost; TListItem *NewItem; ListView1->Items->Clear(); iThreadCount=0; for(i=0;i<=255;i ) { ret = get "." get1 "." get2 "." IntToStr(i); while(iThreadCount>=64) Sleep((unsigned)1000); iThreadCount ; host[i].h_name = (char *)malloc(30); memset(host[i].h_name,0x00,30); LanComputerThread = new TLanComputerThread(&ret,&host[i],&iThreadCount); } while(iThreadCount>0) Sleep((unsigned)1000); for(i=0;i<=255;i ) { if(strlen(host[i].h_name)>0) { NewItem=ListView1->Items->Add(); NewItem->Caption=host[i].h_name; ListView1->LargeImages = ImageList1; ListView1->Refresh(); } free(host[i].h_name); } WSACleanup(); }Func.h 如下 #includeFunc.cpp 內容如下 #include <math.h> #include以上請您試試看吧,有問題再討論看看 |
cashyy
高階會員 發表:117 回覆:322 積分:212 註冊:2004-04-30 發送簡訊給我 |
引言: 這個範例,你參考看看 unit1.h 內容如下真的可以也!不過可不可以解釋一下上面紅色字在做什麼?#include "Func.h" //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; TListView *ListView1; TImageList *ImageList1; TEdit *Edit1; TEdit *Edit2; TLabel *Label1; TLabel *Label2; TComboBox *ComboBox1; void __fastcall Button1Click(TObject *Sender); void __fastcall ListView1DblClick(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); TLanComputerThread *LanComputerThread; };Unit1.cpp如下AnsiString get,get1,get2,ret,aIP; int n,i,iThreadCount; aIP = ComboBox1->Text; n = aIP.Pos("."); get = aIP.SubString(1,n-1); ret = get; aIP = aIP.SubString(n 1,aIP.Length()); n = aIP.Pos("."); get1 = aIP.SubString(1,n-1); ret = ret "." get1; aIP = aIP.SubString(n 1,aIP.Length()); n = aIP.Pos("."); get2 = aIP.SubString(1,n-1); ret = ret "." get2; WORD wVersionRequested=MAKEWORD(1,1); WSADATA wsaData; WSAStartup(wVersionRequested, &wsaData); struct hostent host[256]; struct hostent *tmpHost; TListItem *NewItem; ListView1->Items->Clear(); iThreadCount=0; for(i=0;i<=255;i ) { ret = get "." get1 "." get2 "." IntToStr(i); while(iThreadCount>=64) Sleep((unsigned)1000); iThreadCount ; host[i].h_name = (char *)malloc(30); memset(host[i].h_name,0x00,30); LanComputerThread = new TLanComputerThread(&ret,&host[i],&iThreadCount); } while(iThreadCount>0) Sleep((unsigned)1000); for(i=0;i<=255;i ) { if(strlen(host[i].h_name)>0) { NewItem=ListView1->Items->Add(); NewItem->Caption=host[i].h_name; ListView1->LargeImages = ImageList1; ListView1->Refresh(); } free(host[i].h_name); } WSACleanup(); }Func.h 如下#includeFunc.cpp 內容如下 |
wu-eric
中階會員 發表:14 回覆:82 積分:64 註冊:2004-03-17 發送簡訊給我 |
|
cashyy
高階會員 發表:117 回覆:322 積分:212 註冊:2004-04-30 發送簡訊給我 |
|
SuperRock
一般會員 發表:5 回覆:13 積分:3 註冊:2004-05-20 發送簡訊給我 |
我照著做,但是出現底下error,但是始終找不到'IDGLOBAL.HPP'這個檔案
[C Error] func.cpp(5): E2209 Unable to open include file 'IDGLOBAL.HPP'
我mark掉//#include "IdGlobal.hpp" ,卻出現底下error,能否幫我解決,thanks!!
[C Error] func.cpp(15): E2285 Could not find a match for 'TThread::TThread(AnsiString *)'
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |