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



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

Answer / 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

More Delphi Interview Questions

MS SQL error '17824 Unable to write to ListenOn connection ' what does this error mean?

0 Answers  


How to Extract an icon from a .exe or .dll?

0 Answers  


How to Display the selected row of a DBGrid in a different color?

0 Answers  


Can a Delphi Application Connect to an InterBase Database on Any Platform?

0 Answers  


How to convert a color to a shade of gray?

0 Answers  






How to capture the URL and title of the current webpage being viewed?

0 Answers  


what is Object Activation ?

0 Answers  


What version of Delphi 5 does the Code Explorer come with?

0 Answers  


Can ALTER TABLE statment on Paradox tables removes passwords ?

0 Answers  


Why do I get exception messages even though I am in protected code?

0 Answers  


How to Disable ALT-F4 to prevent form closing

0 Answers  


How to Make the drop-down list appear faster?

0 Answers  


Categories