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
How to Embede a page break in the Rich Edit control ?
what are the different types of dBASE Unique style indexes ?
How to Get current record from a TDBGrid ?
How to Use mouse_event() to similate mouse events?
How to create Data Link File with Windows 2000?
How to turn off ISAPI DLL caching on Windows 2000 and IIS5 ?
How to get the version information for a file?
How to activate different hints for each cell in a grid?
Where can we obtain the help file for the VtChart component?
How to assign a file variable in a Record?
What are the reasons involved in using the interface?
What is the difference between Delphi and Delphi Client/Server?
How to Change windows default printer in code?
How to close the CD Tray in code?
Explain the findclose method?