?
Solved

IP address for Gateway, DNS

Posted on 1999-11-12
7
Medium Priority
?
1,501 Views
Last Modified: 2011-09-20
I am using Delphi 5.0, I will like to know how to retrive the IP address for gateway, subnet mask, DNS (some time more than one) and the domain name.

Thanks
0
Comment
Question by:jlislo
  • 3
  • 3
7 Comments
 

Accepted Solution

by:
redhorn earned 800 total points
ID: 2203358
If what you want is the configured gateway, etc., then consult the Registry.

For domain name & DNS:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP

look at these keys:
Domain
Hostname
NameServer

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans\0002

Look at these keys:
DefaultGateway
IPAddress
IPMask

You might find the information under \0001 or \0003 or perhaps some other number. Remember that these are the configured properties of a given protocol attached to a given interface (e.g., network card). If you know which interface your connection is using, this should be accurate, but to find out your 'actual' IP address and hostname (the ones you are using), consult Winsock. I don't think Winsock can tell you your gateway.

<http://www.gnomehome.demon.nl/uddf/pages/network.htm#network4>
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2203511
These values all don't work with Windows NT. Here the answers from jhance and Ray (taken from UDDF):

{ Q_10218385 by jhance

1) Win95: the IP and MASK are in the registry at:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans

you'll note that there are multiple entries there.  The one you needs depends on which network adapter you are using.

2) WinNT 4.0: also in the registry

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\<adapter service instance>\Parameters\Tcpip

where <adapter service instance> is the service instance of the particular adapter you are interested in.

3) Win98: the Win95 information applies but it also supports the iphlpapi.dll functions AddIpAddress()/DeleteIpAddress() functions.  These also work on NT4.0 SP4 and later under some circumstances.

4) Win2000 - As with NT4.0 and also the iphlpapi.dll functions.

}

// programmatically: Q.10232316 (rwilson) from UDDF
function my_ip_address:longint;
const
  bufsize=255;
var
  buf: pointer;
  RemoteHost : PHostEnt; (* No, don't free it! *)
begin
  buf:=NIL;
  try
    getmem(buf,bufsize);
    winsock.gethostname(buf,bufsize);   (* this one maybe without domain *)
    RemoteHost:=Winsock.GetHostByName(buf);
    if RemoteHost=NIL then
      my_ip_address:=winsock.htonl($07000001)  (* 127.0.0.1 *)
    else
      my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
  finally
    if buf<>NIL then  freemem(buf,bufsize);
    end;
  result:=winsock.ntohl(result);
  end;


Ciao, Mike
0
 

Author Comment

by:jlislo
ID: 2203917
Thanks
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
LVL 10

Expert Comment

by:Lischke
ID: 2205502
Thanks for ignoring me
0
 

Author Comment

by:jlislo
ID: 2208673
Lischke,

Sorry about that! I don't know how to spit the points or direct assign points to you. Is their any way to make it up to you please let me know.

Jammy
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2208706
Unfortunately, you cannot split the points to several answers. Usually, you'd open a dummy questions like "for Lischke..." and can so assign additional points to other experts being usful in the process...

Ciao, Mike
0
 

Author Comment

by:jlislo
ID: 2208826
No problem!
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question