全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1769
推到 Plurk!
推到 Facebook!

請問 INDV Ping 功能取代方式

答題得分者是:christie
larrytyan
一般會員


發表:51
回覆:38
積分:17
註冊:2004-08-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-11-09 17:50:05 IP:210.68.xxx.xxx 訂閱
如題, 我發現 D7 中使用了 INDY 元件 IdICMPClient, 則無法運行於 Windows 7,
所以想請問: 有沒有 Ping 可以傳回成功與否的方法, 並且不用 INDV 元件


christie 的方法雖然看不懂, 但真的很好用
編輯記錄
larrytyan 重新編輯於 2009-11-11 08:15:54, 註解 無‧
larrytyan 重新編輯於 2009-11-13 11:59:31, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-11-10 11:42:23 IP:203.75.xxx.xxx 未訂閱
ind「v」?應該是ind「y」吧,請修正一下主題哦

你的問題
http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=82894
這邊有解答,請看看吧
larrytyan
一般會員


發表:51
回覆:38
積分:17
註冊:2004-08-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-11-11 08:17:25 IP:210.68.xxx.xxx 訂閱
還有別的方法嗎??
更簡單的方法


===================引 用 GrandRURU 文 章===================
ind「v」?應該是ind「y」吧,請修正一下主題哦

你的問題
http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=82894
這邊有解答,請看看吧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-11-11 08:52:44 IP:203.75.xxx.xxx 未訂閱
不用indy就是使用winapi
不過一旦要用winapi,就要有心理準備去看那些很難很難的操作方法

簡單一點的話,就先升級一下你的indy版本(d7可上v10)

剛搜尋的時候突然找到:用delphi实现ping

好像沒用到indy元件?

===================引 用 larrytyan 文 章===================
還有別的方法嗎??
更簡單的方法


===================引 用 GrandRURU 文 章===================
ind「v」?應該是ind「y」吧,請修正一下主題哦

你的問題
http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=82894
這邊有解答,請看看吧
編輯記錄
GrandRURU 重新編輯於 2009-11-11 19:20:42, 註解 無‧
christie
資深會員


發表:30
回覆:299
積分:475
註冊:2005-03-25

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-11-11 16:43:32 IP:59.125.xxx.xxx 未訂閱
function Ping(InetAddress : string) : boolean;
------------------------------------------------------------
Return Value:
On Success, True.
On error, False.
unit PingU;
interface
uses
Windows, SysUtils, Classes;
type
TSunB = packed record
s_b1, s_b2, s_b3, s_b4: byte;
end;
TSunW = packed record
s_w1, s_w2: word;
end;
PIPAddr = ^TIPAddr;
TIPAddr = record
case integer of
0: (S_un_b: TSunB);
1: (S_un_w: TSunW);
2: (S_addr: longword);
end;
IPAddr = TIPAddr;
function IcmpCreateFile : THandle; stdcall; external 'icmp.dll';
function IcmpCloseHandle (icmpHandle : THandle) : boolean;
stdcall; external 'icmp.dll'
function IcmpSendEcho
(IcmpHandle : THandle; DestinationAddress : IPAddr;
RequestData : Pointer; RequestSize : Smallint;
RequestOptions : pointer;
ReplyBuffer : Pointer;
ReplySize : DWORD;
Timeout : DWORD) : DWORD; stdcall; external 'icmp.dll';

function Ping(InetAddress : string) : boolean;
implementation
uses
WinSock;
function Fetch(var AInput: string;
const ADelim: string = ' ';
const ADelete: Boolean = true)
: string;
var
iPos: Integer;
begin
if ADelim = #0 then begin
// AnsiPos does not work with #0
iPos := Pos(ADelim, AInput);
end else begin
iPos := Pos(ADelim, AInput);
end;
if iPos = 0 then begin
Result := AInput;
if ADelete then begin
AInput := '';
end;
end else begin
result := Copy(AInput, 1, iPos - 1);
if ADelete then begin
Delete(AInput, 1, iPos Length(ADelim) - 1);
end;
end;
end;
procedure TranslateStringToTInAddr(AIP: string; var AInAddr);
var
phe: PHostEnt;
pac: PChar;
GInitData: TWSAData;
begin
WSAStartup($101, GInitData);
try
phe := GetHostByName(PChar(AIP));
if Assigned(phe) then
begin
pac := phe^.h_addr_list^;
if Assigned(pac) then
begin
with TIPAddr(AInAddr).S_un_b do begin
s_b1 := Byte(pac[0]);
s_b2 := Byte(pac[1]);
s_b3 := Byte(pac[2]);
s_b4 := Byte(pac[3]);
end;
end
else
begin
raise Exception.Create('Error getting IP from HostName');
end;
end
else
begin
raise Exception.Create('Error getting HostName');
end;
except
FillChar(AInAddr, SizeOf(AInAddr), #0);
end;
WSACleanup;
end;
function Ping(InetAddress : string) : boolean;
var
Handle : THandle;
InAddr : IPAddr;
DW : DWORD;
rep : array[1..128] of byte;
begin
result := false;
Handle := IcmpCreateFile;
if Handle = INVALID_HANDLE_VALUE then
Exit;
TranslateStringToTInAddr(InetAddress, InAddr);
DW := IcmpSendEcho(Handle, InAddr, nil, 0, nil, @rep, 128, 0);
Result := (DW <> 0);
IcmpCloseHandle(Handle);
end;
end.
------
What do we live for if not to make life less difficult for each other?
系統時間:2024-05-16 16:14:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!