How to Get the local internet machine name and IP address?

Answer Posted / venu

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^[i])) + '.');
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;

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to make changes to the VCL code?

1250


How to Test IDispatch Descendants?

1541


compare TProvider Component vs. Provider Property ?

1215


How to prevent application?s main window from showing when application loads?

1349


How to Declare a SafeArray in the type library editor?

1748






How to avoid an access violation when using the move procedure?

1312


How to get a list of CDROM drives on a computer?

1284


How to Access HKEY_LOCAL_MACHINE under NT without Admin?

1292


What directory is the ActiveForm in ?

1415


Does Delphi 5 include Resource Workshop and InstallShield Express?

1708


How to Debug CORBA clients and servers?

2753


How to Load a locale file into the THTML component ?

1326


How to Change RichEdit Font styles with HotKey combinations ?

1280


How to use far pointers?

1623


why you want to make your future in SAP?.

2062