Solved

IP address of both NIC cards

Posted on 2000-05-12
10
294 Views
Last Modified: 2010-04-04
Hello,

How do I get the IP address of the NIC that I use to connect to the internet w/?

I used that local ip function - and that returns the IP address of the machine as seen on my local LAN.

I need to get the ip that Im connected from.

Please help!!!
0
Comment
Question by:regsoft
  • 6
  • 4
10 Comments
 
LVL 1

Expert Comment

by:l8knight
ID: 2806399
I just happen to working on an app that does just that...here's the code. It inserts all IP addresses into a combobox so you can select whichever one you want. I'm using the latest header conversion of winsock 2, but it should work with the conversion that comes with Delphi, if it doesn't let me know and I will send you the link.

function TForm1.GetInterfaceList: Boolean;
var SList: LPSOCKET_ADDRESS_LIST;
    s: TSocket;
    ret,i: Integer;
    BytesRet: DWORD;
begin
  s := Socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
  if s = INVALID_SOCKET then
  begin
    MessageDlg('Socket Failed!', mtError, [mbOK],0);
    Result := False;
  end
  else
  begin
    SList := Nil;
    BytesRet := 0;
    try
      GetMem(SList, 2048);
      ret := WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, Nil, 0, SList, 2048, @BytesRet, Nil, Nil);
      if ret = SOCKET_ERROR then
      begin
        MessageDlg('WSAIoctl Failed (SIO_ADDRESS_LIST_QUERY)!', mtError, [mbOK],0);
        Result := False;
      end
      else
      begin
        for i := 0 to SList^.IAddressCount-1 do
          ComboBox1.Items.Add( inet_ntoa(TInAddr(SList^.Address[i].lpSockAddr.sin_addr)));
        ComboBox1.ItemIndex := 0;
        Result := True;
      end;
    finally
      FreeMem(SList, 2048);
    end;
    CloseSocket(s);
  end;
end;

regards

l8knight
0
 
LVL 1

Expert Comment

by:l8knight
ID: 2806402
whoops just noticed a bug...getmem statement should be before the try clause.

l8knight
0
 

Author Comment

by:regsoft
ID: 2806848
I added winsock to my uses clause - but keep getting an error on this line :
var SList: LPSOCKET_ADDRESS_LIST;

Undeclared identifier : 'LPSOCKET_ADDRESS_LIST'

Am I missing something in the uses clause?
0
 

Author Comment

by:regsoft
ID: 2806856
BTW - Im using D3 on a 98 box.

Tnks for the help so far.
0
 
LVL 1

Accepted Solution

by:
l8knight earned 500 total points
ID: 2807137
Hi regsoft,

      SOCKET_ADDRESS_LIST = packed record
            iAddressCount : Integer;
            Address       : Array [0..0] of SOCKET_ADDRESS;
      end;
      LPSOCKET_ADDRESS_LIST = ^SOCKET_ADDRESS_LIST;

It's declared in the later version of winsock2, so it would probably would be a good idea to download it http://community.borland.com/homepages/dsp/ftp/d20free/winsock2.zip

feel free to ask if you need any more help.

regards

l8knight
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:regsoft
ID: 2807311
Thanks for the help - but I still cant get it to work.

I get it to complile now but when I run it I get a socket failed! error.

Make you a deal - if you can send me source (email it robv@regsoft.com)
that works - Ill up the points to 500.

Thanks again.

-Rob
0
 

Author Comment

by:regsoft
ID: 2822671
Adjusted points from 100 to 500
0
 

Author Comment

by:regsoft
ID: 2822672
That did it - thanks
Sorry for the delay in getting back to you.

0
 

Author Comment

by:regsoft
ID: 2822675
Thanks again for the source and help.
0
 
LVL 1

Expert Comment

by:l8knight
ID: 2823835
no problem

regards

l8knight
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

947 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

21 Experts available now in Live!

Get 1:1 Help Now