Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2009, 06:00 PM
Hitman Hitman is offline
Senior Member
 
Join Date: Oct 2006
Location: A nice place on earth
Posts: 309
Lightbulb How to get network info

Hi guys,
I need to get,

Ip, subnet mask, default gateway and wan ip from the local computer,
any ideas or examples about how to do this?

Cheers
__________________
ERRARE HUMANUM EST
Reply With Quote
  #2  
Old 09-17-2009, 07:37 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,764
Default

Code:
USES WinSock;
..............................................................
..............................................................
Function GetIPAddress: String;
var
         phoste  : PHostEnt;
         Buffer  : array[0..100] of char;
         WSAData : TWSADATA;
begin
         Result := '';
         if WSASTartup($0101, WSAData) <> 0 then
            exit;

         GetHostName(Buffer,Sizeof(Buffer));
         phoste := GetHostByName(buffer);
         if phoste = nil then
            Result := '127.0.0.1'
         else
            Result := StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));

         WSACleanup;
end;
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 09-18-2009, 06:44 AM
Hitman Hitman is offline
Senior Member
 
Join Date: Oct 2006
Location: A nice place on earth
Posts: 309
Default

Quote:
Originally Posted by Jasser View Post
Code:
USES WinSock;
..............................................................
..............................................................
Function GetIPAddress: String;
var
         phoste  : PHostEnt;
         Buffer  : array[0..100] of char;
         WSAData : TWSADATA;
begin
         Result := '';
         if WSASTartup($0101, WSAData) <> 0 then
            exit;

         GetHostName(Buffer,Sizeof(Buffer));
         phoste := GetHostByName(buffer);
         if phoste = nil then
            Result := '127.0.0.1'
         else
            Result := StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));

         WSACleanup;
end;
Thanks mate
This picks the LAN IP only.
__________________
ERRARE HUMANUM EST
Reply With Quote
  #4  
Old 09-18-2009, 03:44 PM
nester261 nester261 is offline
Moderator
 
Join Date: Jan 2004
Location: UK
Posts: 616
Default

To get the WAN IP use:

Code:
var
thisismyip, IP : String;
l, p1, p2 : integer;
IdHttp1 : TIDhttp;
begin
IdHttp1:= tidhttp.Create(nil);
IdHttp1.HandleRedirects := true;
thisismyip := IdHttp1.get('http://www.showmemyip.com');
L := Length('');
P1 := Pos('',thisismyip);
P2 := Pos('',thisismyip);
IP := Copy(thisismyip,P1 + L, P2 - P1 - L);
IdHttp1.Free;
IPEdt.Text := IP;
* You will need an IdHTTP Component
__________________
"Where there's a will, there's always a way."

-- The Hon Robert Nester Marley O.M. - aka Bob Marley!
Reply With Quote
  #5  
Old 09-18-2009, 05:55 PM
Hitman Hitman is offline
Senior Member
 
Join Date: Oct 2006
Location: A nice place on earth
Posts: 309
Default

Quote:
Originally Posted by nester261 View Post
To get the WAN IP use:

Code:
var
thisismyip, IP : String;
l, p1, p2 : integer;
IdHttp1 : TIDhttp;
begin
IdHttp1:= tidhttp.Create(nil);
IdHttp1.HandleRedirects := true;
thisismyip := IdHttp1.get('http://www.showmemyip.com');
L := Length('');
P1 := Pos('',thisismyip);
P2 := Pos('',thisismyip);
IP := Copy(thisismyip,P1 + L, P2 - P1 - L);
IdHttp1.Free;
IPEdt.Text := IP;
* You will need an IdHTTP Component
Thank you
__________________
ERRARE HUMANUM EST
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:57 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.