?
Solved

IP address of both NIC cards

Posted on 2000-05-12
10
Medium Priority
?
308 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

718 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