R
Roadsign
Unregistered / Unconfirmed
GUEST, unregistred user!
//下面这段是将网址转换成IP,函数没问题,SvrNameToIP(hostname)很好用,只是
//如果网址错误或PING不通该怎么办?怎样返回信息?比如返回Showmessage('wrong!')
//use winsock
function SvrNameToIP(const SvrName: string): string;
type
PPInAddr = ^PInAddr;
var
phe: PHostEnt;
pp: PPInAddr;
GInitData: TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
phe := GetHostByName(PChar(SvrName));
if phe = nil then
Exit;
pp := PPInAddr(phe^.h_addr_list);
if pp^ <> nil then
Result := StrPas(inet_ntoa(pp^^));
WSACleanup;
end;
//程序没问题,只是偶以前没接触过网络这块,看不太懂……
//如果网址错误或PING不通该怎么办?怎样返回信息?比如返回Showmessage('wrong!')
//use winsock
function SvrNameToIP(const SvrName: string): string;
type
PPInAddr = ^PInAddr;
var
phe: PHostEnt;
pp: PPInAddr;
GInitData: TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
phe := GetHostByName(PChar(SvrName));
if phe = nil then
Exit;
pp := PPInAddr(phe^.h_addr_list);
if pp^ <> nil then
Result := StrPas(inet_ntoa(pp^^));
WSACleanup;
end;
//程序没问题,只是偶以前没接触过网络这块,看不太懂……