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
Why reusing or inheriting from a Remote Data Module is not a good idea?
How to Change delphi default directory?
How to create a Resource only DLL?
How to easily move a Window control at runtime?
How to Calculate an angle from two points?
How to DetermineDrive Type ?
How to have a TBitBtn component that has a word wrapped caption?
How to move a string into a TMemoryStream or TFileStream?
How to Trap scrolling messages for the ScrollBars of a TScrollBox ?
How to Calculatea point using angles and distance?
How to Prevent the TEdit component from beeping when invalid ?
How is the memory used within an object in delphi?
what are the different String Trim functions?
How to create SQL queries with SQL Builder?
How to Launch default browser on a URL?