Delphi NET - descobrindo IPs |
Top Previous Next |
|
{$APPTYPE CONSOLE} program getip;
uses System, System.Net, Borland.Delphi.SysUtils;
var strMachineName : String; ipHost : IPHostEntry; ipAddr : array of IPAddress; count : Integer; begin
//Get the Host Name strMachineName := Dns.GetHostName(); Console.WriteLine('Host Name: ' + strMachineName);
//Get the Host by Name ipHost := Dns.GetHostByName(strMachineName);
//You can also query the DNS database for info on a //website like users.chello.be //In that case replace the above line as: //ipHost := Dns.GetHostByName('users.chello.be')
//Get the list of addresses associated with the host in an array ipAddr := ipHost.AddressList;
//Enumerate the IP Addresses For count := 0 To length(ipAddr) - 1 do
Console.Write(Format('IP Addresses %d: %s ', [count, ipAddr[count].ToString])); end. |