Get MAC Address and IP number

Hi,

All of us know how to get the MAC Address and IP number using Windows functions, because we have a lot of examples on internet. But now in Mac platform, how we can get this information too?

Thanks in advance.
0
romulo
10/30/2011 8:35:03 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

7 Replies
4613 Views

Similar Articles

[PageSpeed] 56
Get it on Google Play
Get it on Apple App Store

Ralph Wesseling wrote:
>> {quote:title=romulo nascimento wrote:}{quote}
>> Hi,
>> 
>> All of us know how to get the MAC Address and IP number using
>> Windows functions, because we have a lot of examples on internet.
>> But now in Mac platform, how we can get this information too?  
>> 
>> Thanks in advance.
> 
> I would love to know this also - anyone?

Try this:

{code}
program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Posix.Base,
  Posix.SysSocket,
  Posix.NetIf,
  Posix.NetinetIn,
  Posix.ArpaInet;

type
  u_char = UInt8;
  u_short = UInt16;
  sockaddr_dl = record
    sdl_len: u_char;    //* Total length of sockaddr */
    sdl_family: u_char; //* AF_LINK */
    sdl_index: u_short; //* if != 0, system given index for interface */
    sdl_type: u_char;   //* interface type */
    sdl_nlen: u_char;   //* interface name length, no trailing 0 reqd. */
    sdl_alen: u_char;   //* link level address length */
    sdl_slen: u_char;   //* link layer selector length */
    sdl_data: array[0..11] of AnsiChar; //* minimum work area, can be larger;
                                        //contains both if name and ll address */
  end;
  psockaddr_dl = ^sockaddr_dl;

const
  IFT_ETHER = $6;  //if_types.h

function getifaddrs(var ifap: pifaddrs): Integer; cdecl;
   external libc name _PU + 'getifaddrs';
{$EXTERNALSYM getifaddrs}

procedure freeifaddrs(ifp: pifaddrs); cdecl;
   external libc name _PU + 'freeifaddrs';
{$EXTERNALSYM freeifaddrs}

var
  ifap, Next: pifaddrs;
  sdp : psockaddr_dl;
  MacAddr : array[0..5] of Byte;
  cur: AnsiString;
  ip: AnsiString;
begin
  try
    if getifaddrs(ifap) <> 0 then
      RaiseLastOSError;
    try
      WriteLn('');

      SetLength(ip, INET6_ADDRSTRLEN);
      Next := ifap;
      while Next <> nil do
      begin
        if cur <> AnsiString(Next.ifa_name) then
        begin
          cur := AnsiString(Next.ifa_name);
          Write(cur);
          WriteLn(': flags: ' + IntToHex(Next.ifa_flags, 4));
        end;
        case Next.ifa_addr.sa_family of
          AF_LINK :
            begin
              sdp := psockaddr_dl(Next.ifa_addr);
              if sdp.sdl_type = IFT_ETHER then
              begin
                Move(Pointer(PAnsiChar(@sdp^.sdl_data[0]) + sdp.sdl_nlen)^, MacAddr, 6);
                WriteLn(Format('  ethernet ID: %x:%x:%x:%x:%x:%x',
                   [MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]]));
              end;
            end;
          AF_INET, AF_INET6:
          begin
            FillChar(Pointer(ip)^, INET6_ADDRSTRLEN, #0);
            inet_ntop(Next.ifa_addr.sa_family, @psockaddr_in(Next.ifa_addr)^.sin_addr, PAnsiChar(IP), INET6_ADDRSTRLEN);
            WriteLn('  IP: ' + ip);
          end;
        end;
        Next := Next.ifa_next;
      end;
    finally
      freeifaddrs(ifap);
    end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
{code}

-- 
Arno Garrels
0
Arno
1/3/2012 7:49:52 PM
Thanks Arno,

That did the trick
0
Ralph
1/4/2012 2:14:23 AM
Thanks a lot Arno, you are "The man".
0
romulo
1/4/2012 12:16:49 PM
"Arno Garrels" <arno.garrels@gmx.de> schrieb im Newsbeitrag news:432484@forums.embarcadero.com...
> Ralph Wesseling wrote:
>>> {quote:title=romulo nascimento wrote:}{quote}
>>> Hi,
>>> 
>>> All of us know how to get the MAC Address and IP number using
>>> Windows functions, because we have a lot of examples on internet.
>>> But now in Mac platform, how we can get this information too?  
>>> 
>>> Thanks in advance.
>> 
>> I would love to know this also - anyone?
> 
> Try this:
[..]

Well, inet_ntop() doesn't seem to well format IPv6 addresses.
Find a better routine, i.e. such as  ICS' WSocketIPv6ToStr() from
its IPv6 branch: svn://svn.overbyte.be/ics/branches/icsipv6.
Both, username und password "ics".

-- 
Arno Garrels
0
Arno
1/5/2012 7:54:09 PM
Hi Arno,

Indeed. I receive a print in my console. But how can I implement this in a function?
I only want my primair network mac-address. (under OSX)

Can I use this like:
if getmacadress = 14:10:9H:D5:9D:CD then ....

I want use the function for licensing purposes.

Forwarded thanks!
0
Frank
3/18/2013 8:09:46 PM
Frank Ignoul wrote:
> Hi Arno,
> 
> Indeed. I receive a print in my console. But how can I implement this
> in a function?

The provided code should give you an idea.

-- 
Arno
0
Arno
3/20/2013 6:13:00 PM
> {quote:title=romulo nascimento wrote:}{quote}
> Hi,
> 
> All of us know how to get the MAC Address and IP number using Windows functions, because we have a lot of examples on internet. But now in Mac platform, how we can get this information too?
> 
> Thanks in advance.

I would love to know this also - anyone?
0
Ralph
11/6/2013 8:34:35 PM
Reply:

Similar Artilces:

Get IP address and MAC address
Hi there! How can get ip address and mac address from command shell without root attributes(I can't use 'ifconfig'). Thank you in advance. -- [Adri�n C�rdoba] ------------------------------------------------------------------------ aecordoba wrote: > Hi there! > How can get ip address and mac address from command shell without root > attributes(I can't use 'ifconfig'). > Thank you in advance. > > /sbin/ifconfig -- Vahis aecordoba wrote: > Hi there! > How can get ip address and mac address from command shell wi...

How to get MAC address & IP address?
Dear all how to get the MAC address & IP address using PowerBuilder 6.5? thanks! Michael On Wed, 16 Jan 2002 22:42:51 +0800, "Michael" <michaell@hknet.com> wrote: >Dear all > > how to get the MAC address & IP address using PowerBuilder 6.5? > thanks! > >Michael > For IP address see http://eric.aling.tripod.com/PB/tips/pbtip14.htm -- Boris Gasin [TeamSybase] mailto:bgasin@dynamictechgroup.com Close to NJ? Join the NJ Sybase Tools User Group http://www.njpbug.org/njpbug/join/join.asp On Wed, ...

How to fix get IP-MAC pairs code below from Delphi 7 to Delphi 2009 ?
How to get All IP - MAC address pairs on local PC by Delphi 2009 ? The Code below can get correct answer on Delphi 7, but get error answer on Delphi 2009. How to fix ? or Are there the better method ? // Delphi 7 (Delphi 2009 failed) // // Get Alll IP-MAC address pairs on local PC // unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; function GetIPMAC: String; const ANY_SIZE = 1; MAX_ADAPTER_ADDRESS_LENGTH = 8; // arb. MAX_INTERFACE_NAME_LEN = 256; { mrapi.h } MAXL...

Getting the MAC Address, ISP IP, Client IP of the user and verifying it to let the Login
Hi Everyone,Any help for getting the IP address of the client, its MAC address and its ISP IP so that after checking these he will be let into login.RegardsSadeed Remember to click “Mark as Answer” on the post If you get answer from this post(s) !Thanks GuysRegardsSid  Is this over the LAN or over the internet?Over the internet, you can only get the apparent IP address of the user (which may be the address of the external router).As to getting the IP of the ISP, then closest might be do a traceroute and take the last but IP address. Don't forget to click "Mark as Answer"...

Getting MAC and TCP/IP addresses
Hi, Does anyone know how to determine the MAC address of an installed network interface card from within PowerBuilder? How about the current TCP/IP address? I think there are API calls for these items, but I can not seem to find them anywhere. Thanks for the help! Chris Street ctstreet@hydro.mb.ca In article <36EED522.65341440@hydro.mb.ca>, ctstreet@hydro.mb.ca says... > Hi, > > Does anyone know how to determine the MAC address of an installed > network interface card from within PowerBuilder? How about the current > TCP/IP address? > >...

Get Local IP Address with Delphi 2009
Hi all How can I get the local IP Address with Delphi 2009? All examples i find are only running with Delphi 2007 because they are not using AnsiChar. Thank you for your help Herbert > > All examples i find are only running with Delphi 2007 because they are not > using AnsiChar. Replace Char with AnsiChar in the examples ? I got this off the Internet and I have used it in several projects. I changed char to ansichar for Delphi 2009 and it works. This function uses the winsock unit. function TForm1.GETIPAddress(): string; type pu_long = ^u_long; var varTWS...

Getting MAC address or Serial number of Hard disk
Hi, I would like to track whether my client come back my site or not. Is it possible to get MAC address or Serial Number of hard disk of client PC accessing our site?ThanksTran Hong Quang There is no direct way of doing this in ASP.NET. However, you could use WMI in ASP.NET, and I beleive WMI can tell you that information.Cheers,       Kevin JonesMy Blog...

IP address vs MAC address
Ok somebody explain this to me. I understand how IP addresses are issued(well sort of...lol) Is it one IP address to one MAC address?(not accounting for non routable IP space) I understand there can only be one WAN facing IP address per machine/MAC/NIC/etc realizing multiple NICs possible on one computer. If that is the case then how can say a Comcast DHCP server keep from issuing an IP to a MAC address that another provider has already issued an IP for? In this case perhaps someone has made up a MAC address to use in their router for cloning purposes. Or does it really ...

Is there a way to get IP/Host name given the MAC address?
------_=_NextPart_001_01C19DA2.7BFEE650 Content-Type: text/plain; charset="Windows-1255" > Hi, > > Does anybody know's a way to get a Host name > If I have a Mac address both in pc and sun? > (it's the same as RARP but I don't know how to do it using command line ) > > THX > > ------_=_NextPart_001_01C19DA2.7BFEE650-- 1. SUN without DNS: arp -a 2. SUN with DNS: arp -a; nslookup hostname For Example: % arp -a | grep '00:55:' Net to Media Table Device IP Address Mask Flags...

how to find ip address from mac address?
It happened more than once. At a customer's office, there is a device with an unknown ip address. We know its mac address. The ip address might be different from the network. For example, the customer's network might be 10.1.0.0/16, whereas that device might have the ip address 192.168.200.123/24. For example, it might be a managed switch that has kept its default ip address. So, it works as a switch, but I cannot manage it. Apart from a sniffer, is there a (free?) software that can scan the network and find ip addresses of all hosts, and/or only of those whose mac address ...

IP Number/ IP Address Array
I need to convert the first column of a list of IP numbers to IP addresses. I created an array of my list but am stumped on how to convert the numbers. File: 180884576 imstrmcs05 180884577 imstrmcs06 180884578 imstrmcs07 180884579 imstrmcs08 180884580 imstrmcs09 180884581 imstrmcs10 Script: # Properly formatting into an array open(IPLIST, "file") || die "couldn't open the file"; while ($x = <IPLIST>) { chop $x; @arr = split /\s+/,$x; print "@arr\n"; } # Converting IP number to IP address...

Virtual IP Address (Mac Addressing)
We are planning a 26node cluster Groupwise implementation early next year. After meeting with our Network people, one of them posed the question if Server A (connected to Switch A) fails over to Server B which is connected to Switch B (Will the virtual mac IP address that fails over to Server B be recorded correctly). I was under the impression that the application layer managed it, but we need clarification for Netware. Thanks. Novell's fail-over works by only moving the IP address of a resource and not the MAC address. Therefore, the fail-over is completely transparent ...

IP Address allocation by mac address
Is it possible to give a specific mac address a fixed IP address when it requests an address from the DHCP server? mike.dawson@scarborough.gov.uk schrieb: >Is it possible to give a specific mac address a fixed IP address when it >requests an address from the DHCP server? Yes. Just create an ip-address-object with manual assignment type in the DNS/DHCP management console. Enter the mac-address, unload and reload the dhcpsrvr module and release and renew the address at the workstation. Important: Don�t touch the client identifier field, when creating the object. J...

Web resources about - Get MAC Address and IP number - embarcadero.delphi.firemonkey

File:Ipv6 address.svg - Wikipedia, the free encyclopedia
I, the copyright holder of this work, release this work into the public domain . This applies worldwide. This file contains additional information, ...

Civil Defence continues to tackle blaze at The Address Downtown Dubai - The National
A lower part of the hotel building was still on fire at 8am Friday, a resident and a photographer from The National said.

Dubai fire at Address Downtown: Photographer’s narrow escape
A PHOTOGRAPHER has told of a harrowing 30 minutes he spent trapped on a ledge metres from the raging inferno that engulfed a skyscraper in Dubai ...

Dubai hotel fire: At least 16 injured as officials probe cause of blaze at The Address Downtown hotel ...
Investigators in Dubai are working to determine the cause of a fire that engulfed a 63-storey luxury hotel on New Year's Eve.

GOP Establishment Has No Problem with Hillary Win, Won’t Address the Clintons’ War on Women
Breitbart News' John Nolte had a perceptive piece this weekend on the GOP Establishment having no desire to beat Hillary Clinton or elect Donald ...

President Obama previews his final State of the Union address
The president is scheduled to deliver his final address next Tuesday to both chambers of Congress

Cameron pledges to address roots of UK Islamist extremism in 2016
... plan of social reform to be built on the country's recovering economic foundations. Prime Minister David Cameron pledged on Friday to address ...

Fire at downtown Dubai's highrise Address hotel
CNN Fire at downtown Dubai's highrise Address hotel CNN (CNN) A massive fire broke out Thursday night at the high-end Address hotel in downtown ...

'Castle' Season 8 Co-Showrunners Address Rumors ABC Series Will Be Cancelled
Will "Castle" be cancelled after season 8? " Castle " co-showrunners Terence Paul Winter and Alexi Hawley recently addressed rumors that the ...

Pathankot attack: Time for PM Modi to dump NRIs, address nation on language of India-Pak dialogue
I believe that for the Narendra Modi government, we NRIs have become a cop-out of the first order. We have been singularly responsible for having ...

Resources last updated: 1/7/2016 4:53:08 PM