Link to home
Start Free TrialLog in
Avatar of gaafer5
gaafer5

asked on

how can i get my computer ip's addresses?

i have more than one nic(network interface card) how can i get the addresses of these cards programatically using delphi.
ASKER CERTIFIED SOLUTION
Avatar of smurff
smurff

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi gaafer hope this code will help you. You should just insert into your form TLabel, TEditBox and TButton. When you will enter name of computer and click Button it will show you ip address of corresponding computer.


function HostToIP(Name: string; var Ip: string): Boolean;
var
  wsdata : TWSAData;
  hostName : array [0..255] of char;
  hostEnt : PHostEnt;
  addr : PChar;
begin
  WSAStartup ($0101, wsdata);
  try
    gethostname (hostName, sizeof (hostName));
    StrPCopy(hostName, Name);
    hostEnt := gethostbyname (hostName);
    if Assigned (hostEnt) then
      if Assigned (hostEnt^.h_addr_list) then begin
        addr := hostEnt^.h_addr_list^;
        if Assigned (addr) then begin
          IP := Format ('%d.%d.%d.%d', [byte (addr [0]),
          byte (addr [1]), byte (addr [2]), byte (addr [3])]);
          Result := True;
        end
        else
          Result := False;
      end
      else
        Result := False
    else begin
      Result := False;
    end;
  finally
    WSACleanup;
  end
end;

procedure TForm1.Button1Click(Sender: TObject);
var IP: string;
begin
 if HostToIp(Edit1.Text, IP) then Label1.Caption := IP
end;


Regards Ferhad
Avatar of smurff
smurff

isnt that exactly what Ive put?????? look at the code
Only Ferhads code can only get one nic card, my code you can get them all.
Smurff
Getting the IP address, mask, broadcast address etc for all TCP/IP interfaces

http://www.delphi3000.com/article.asp?ID=1430

To read this article you must register. After that you can read 50 old articles and all that day posted Delphi tips ( this mean that is recomanded to visit every day the site to get tips for free - it's a way of owner to keep a big number of visits on her site ) for FREE .

Is a very good site.
procedure PobierzTypPolaczenia(var typ: string);
var
        flags: DWORD;
begin
        typ := '';
        if InternetGetConnectedState(@flags, 0) then
        begin
                if (flags and LAN) = LAN then typ := 'LAN';
                if (flags and MODEM) = MODEM then typ := 'Modem';
                if (flags and PROXY) = PROXY then typ := 'Proxy';
        end;
end;

Don't forget to add WinInet to uses...
And now typ has a type of your connection...
That's easier, isn't it? :P

anAKiN
anAKiN , I think that the topic of this question is IP addresses and not the type of connection .
Theres a few solutions there that work fine.

Ginsonic,
Nice site, Found some great stuff on there thanks.
gaafer5:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.