Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

Does the BDE use Client side or server side cursors for MSSQL?

0 Answers  


How to keep seconds from being included in the display when using TDateTimePicker?

0 Answers  


How to create a dynamic array of TPoints to draw a polygon?

0 Answers  


How tough is it to learn Delphi?

0 Answers  


How to Hide the windows taskbar?

0 Answers  






When I use the Glyph property, how do I know which color is transparent?

0 Answers  


How to Check available disk space on large drives?

0 Answers  


How to convert a .dfm file to text and vise versa?

0 Answers  


What are the different types of pointers used in delphi?

0 Answers  


How to Test whether you are connected to the internet ?

0 Answers  


How to Declare a SafeArray in the type library editor?

0 Answers  


How to Create a palette with more than one entry ?

0 Answers   Wipro,






Categories