Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

All netowrk interfaces list (ip and subnetmask)

Posted on 2003-11-17
5
230 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

790 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