怎樣用delphi製作一個IPhunter(獨孤劍客的IP獵人) (轉)

worldblog發表於2007-12-02
怎樣用delphi製作一個IPhunter(獨孤劍客的IP獵人) (轉)[@more@]

有人說現在的員成了組裝工人,其實很有道理,利用模組+少量程式碼就可以實現, 5.0提供了豐富的inte控制元件,利用 客戶端-服務端就可以解決問題。關鍵的控制元件是ServerSocket,我們模仿IPhunter的介面用一個button1(按鈕),一個combobox1(用於顯示),這三個最基本的控制元件放置到空白窗體上就可以開始寫程式碼了。
首先,這個combobox1必須能顯示多個IP,我們定一個變數y來累加combobox1.items[y],
var y:integer;
我們的思路如下,當ServerSocket活動的port(埠)收到基於TCP/IP的連結請求時候,返回對方的IP值,傳遞給combobox顯示出來。由button1控制ServerSocket的啟用,也就是開啟關閉埠。
我們在ServerSocket的On ClientConnect事件中加入一下程式碼
procedure TForm1.ServerSocket11ClientConnect(Sender: T;
Socket: TCustomWinSocket);
begin
combobox1.Items.Insert(y,'');//加入一條空紀錄
combobox1.Items[y]:=socket.RemoteAddress;//獲取對方的
label1.Text:='共捕獲'+inttostr(y+1)+'個IP';//用一個標籤來顯示一共抓了多少IP
y:=y+1;//計數變數加1
socket.Close;
end;
現在,將button1的caption屬性設定為 '開始',在它的單擊事件中加入以下程式碼
procedure TForm1.Speeutton7Click(Sender: TObject);
begin
if speedbutton7.Caption='開始' then
begin
serversocket11.Port:=80;//這句可以在serversocket屬性中設定,捕獲的連線
ServerSocket11.Active:=true;//啟用埠
speedbutton7.Caption:='停止';
end
else
begin
serversocket11.Active:=false;//關閉埠
speedbutton7.Caption:='開始';
combobox1.Clear;//結束捕獲,清空歷史資訊
y:=0;//計數變數復位
end;
end;


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-987334/,如需轉載,請註明出處,否則將追究法律責任。

相關文章