怎样根据域名取得与之相应的IP地址(50分)

  • 主题发起人 主题发起人 mathboy
  • 开始时间 开始时间
M

mathboy

Unregistered / Unconfirmed
GUEST, unregistred user!
比如www.gao.com的IP地址是多少
 
nslookup www.gao.com
66.115.143.196
 
用PING命令
 
转一个

uses Winsock;

function GetIPFromHost(var HostName, IPaddr, WSAErr: string): Boolean;
type
Name = array[0..100] of Char;
PName = ^Name;
var
HEnt: pHostEnt;
HName: PName;
WSAData: TWSAData;
i: Integer;
begin
Result := False;
if WSAStartup($0101, WSAData) <> 0 then begin
WSAErr := 'Winsock is not responding."';
Exit;
end;
IPaddr := '';
New(HName);
if GetHostName(HName^, SizeOf(Name)) = 0 then
begin
HostName := StrPas(HName^);
HEnt := GetHostByName(HName^);
for i := 0 to HEnt^.h_length - 1 do
IPaddr :=
Concat(IPaddr,
IntToStr(Ord(HEnt^.h_addr_list^)) + '.');
SetLength(IPaddr, Length(IPaddr) - 1);
Result := True;
end
else begin
case WSAGetLastError of
WSANOTINITIALISED:WSAErr:='WSANotInitialised';
WSAENETDOWN :WSAErr:='WSAENetDown';
WSAEINPROGRESS :WSAErr:='WSAEInProgress';
end;
end;
Dispose(HName);
WSACleanup;
end;



procedure TForm1.Button1Click(Sender: TObject);
var
Host, IP, Err: string;
begin
if GetIPFromHost(Host, IP, Err) then begin
Edit1.Text := Host;
Edit2.Text := IP;
end
else
MessageDlg(Err, mtError, [mbOk], 0);
end;

 
Include the ComObj unit in your unit as shown below
uses ComObj;

var
oExec: Variant;

begin
oExec:=CreateOleObject('Dynu.Exec');

//Execute the command 'ipconfig' and display its result.
MessageDlg(oExec.execute('ipconfig'), mtInformation, [mbOK], 0);

//Execute the command 'nslookup -type=mx microsoft.com' and display its result.
MessageDlg(oExec.execute('nslookup -type=mx microsoft.com'), mtInformation, [mbOK], 0);

//Execute the batch file and display its result.
MessageDlg(oExec.execute('c:/bin/somejob.bat'), mtInformation, [mbOK], 0);

end;


有好的控件可以实现的吗? 以前TNMhttp就很好用的.
 
后退
顶部