Solved

All netowrk interfaces list (ip and subnetmask)

Posted on 2003-11-17
5
226 Views
Last Modified: 2010-04-05
Hi.
I want to obtain a list of ALL available network interfaces on a system. I want a list of ip-subnetmask pairs, one pair for each subnet the computer is on. The computer may have more than one network cards, or the network card may have more ips assigned to it, or I may have a netorkcard and an active dial-up connection, etc. Basicaly, I want to see all the interfaces, just like you do when you run the "ifconfig" command on a Unix system. I only need the ip and subnetmask for each. I hope you got it :)

I've done some digging in the registry and I kinda found there what I am looking for, but the information there is rather inconsistent (dial-up info is in once place, network card info in another place, etc.)
I need a consistent solution for listing all netowrk interfaces that will work on all (most) windows versions (95, 98, ME, XP, 2k, etc.)

Also, it would be nice to be notifyed when any of these change (under win XP, if the user changes the ip, I want to be notifyed, or if the user connects/disconnects trough dial-up). This part is not very important cos I can always check manualy from time to time.
0
Comment
Question by:Muqker
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
gmayo earned 300 total points
ID: 9769638
There is a previous question:
http://oldlook.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20352829.html?query=list+all+network+cards&searchType=topic

I do have another solution but I need to find it first... watch this space if nobody else gets here first!

Geoff M.
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9769664
procedure GetIPs(s : TStrings);
type
      TaPInAddr = Array[0..10] of PInAddr;
      PaPInAddr = ^TaPInAddr;
var
      phe : PHostEnt;
      pptr : PaPInAddr;
      Buffer : Array[0..63] of Char;
      i : Integer;
      GInitData : TWSAData;
begin
      WSAStartup($101, GInitData);
      s.Clear;
      GetHostName(Buffer, SizeOf(Buffer));
      phe := GetHostByName(buffer);
      if phe <> nil then begin
            pPtr := PaPInAddr(phe^.h_addr_list);
            I := 0;
            while pPtr^[I] <> nil do
            begin
                  s.Add(inet_ntoa(pptr^[I]^));
                  Inc(I);
            end;
            WSACleanup;
      end;
end;

That will get all the IP addresses (my PC has 2: one for the ethernet card; one for the USB broadband modem). There is a much longer example on http://oldlook.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10126142.html which gets the subnet mask as well.

Geoff M.
0
 
LVL 8

Expert Comment

by:gmayo
ID: 10086771
Any good?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now