Obtaining MAC address in C program

Hello there,
I wish to obtain the MAC address of the primary ethernet card on a Solaris OS via C. This program is invoked many times/second so calling an external program is not really suitable.
The MAC address is being obtained for the purpose of providing a low-level software lock/key system (low level meaning I am aware it's relatively trivial to circumvent).
Paul.

Hello again.
I found out that the SIOCGARP ioctl will get the ARP entry of a certain IP address in the ethernet. Root access is not required.
The following program will print the ethernet MAC addresses of all IP networks (including dial-up and 127.0.0.1).
For Dial-up and 127.0.0.1 "No ethernet address" will be reported. If you have multiple network cards it may be a problem to find out the MAC address of the main board.
On my Blade-1000 the following output is produced:
lo0: 127.0.0.1 - No ethernet address.
eri0: 192.168.178.18 - 08:00:20:FB:2F:78Here is the program:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
main(int argc,char *argv)
    unsigned char eth_addr[6];
    int i,j,sock;
    unsigned char *p;
    struct lifconf lic;
    struct lifreq lifrs[30];
    struct lifnum num;
    struct arpreq ar;
    struct sockaddr_in *soap,*soap2;
    /* Enumerate all IP addresses of the system */
    sock=socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);
    num.lifn_family=AF_INET;
    num.lifn_flags=0;
    ioctl(sock,SIOCGLIFNUM,&num);
    lic.lifc_family=AF_INET;
    lic.lifc_flags=0;
    lic.lifc_len=sizeof(lifrs);
    lic.lifc_buf=(caddr_t)&(lifrs[0] );
    ioctl(sock,SIOCGLIFCONF,&lic);
    /* Get the ethernet address for each of them */
    for(i=0;i<num.lifn_count;i++)
        /* Get IP address */
        ioctl(sock,SIOCGLIFADDR,&(lifrs[ i ]));
        soap=(struct sockaddr_in *)&(lifrs[ i ].lifr_addr);
        soap2=(struct sockaddr_in *)&(ar.arp_pa);
        *soap2=*soap;
        /* Print IP address */
        p=(unsigned char *)&(soap->sin_addr);
        printf("%s: %u.%u.%u.%u - ",lifrs[ i ].lifr_name,
            p[0],p[1],p[2],p[3]);
        /* Get ethernet address */
        if(ioctl(sock,SIOCGARP,&ar)<0)
            printf("No ethernet address.\n");
        else
            p=(unsigned char *)&(ar.arp_ha.sa_data);
            printf("%02X:%02X:%02X:%02X:%02X:%02X\n",
                p[0],p[1],p[2],p[3],p[4],p[5]);
    close(sock);
}Martin

Similar Messages

  • How to set the IP and MAC address in C program?

    My working environment is Sun250 Server, Solaris 7 operating system. I encountered a problem ---- How to set the IP and MAC address in C program to make the system change it IP & MAC at runtime?
    Any idea is welcome! Thanks!

    Hi
    As a simplest possible solution, you can use the system command
    to run ifconfig that can set both the mac address and the IP address of the system. You will have to use setuid though.
    Or you can use the DLPI calls ( do a man DLPI or search for a
    Sun documentation on the same at http://soldc.sun.com) to write
    a pure C program.
    HTH
    Shridhar

  • Obtain MAC Address from 250 iPads

    Hi all,
    I have taken delivery of 250 iPads which I am configuring with OSX Server on a MAC Mini. So far, so good!
    Our wireless network uses MAC Address authentication so I have to add each MAC Address to our Cisco Wireless controller.
    Without having to go to Settings > General > About and write down the MAC Address from every device, is there a way to obtain the MAC Address from either the box using the barcode, or maybe an App that loads up on screen and shows the MAC Address of the device in a barcode format that I can then quickly scan into an Excel spreadsheet and import?
    I feel that i'm about to waste a lot of time going on to each iPad and obtaining the MAC Address
    Thanks in advance
    Regards
    Jim

    If you have the ability to plug them into Apple Configurator, you can connect them with a USB hub and update and supervise them.  This will let you export MAC Addresses and Serial numbers from Configurator to a CSV file that you can use to upload to your wireless controller.  If you need to, be sure to Unsupervise the iPads when you are done.
    The info you're looking for may also be available through GSX, but I'm not familiar with everything you can use it for on your end.

  • Obtaining MAC addresses of machines on local network

    Hello, I have written a small network management program in Java (used to remotely turn our machines on and off)
    Off via starting an external program (beyondexecv2), and on via creaing the Wake On Lan magic packet.
    Currently it looks up the MAC addresses in a textfile of mahinenames->mac address.
    I'd like to be able to scan the network and automatically pick up the MAC addresses of any machine that is currently on.
    I have seen other network scan programs that do this, is it possible in Java?
    Yours
    PPage

    Thanks Omkara,
    Thats nearly the way I've decided to do it (after finding similar on another thread)
    Basically need to itterate through my list of machine names (or get them from a standard scan of the IP range), and for each run the ping command on the ip/machinename, then immidiatly run the arp -a command and parse its output looking for the IP address of the machine, and that will give its corrosponding MAC address.
    Problem sorted.
    Cheers for the help though.

  • Obtain MAC address!!!

    Hi!
    I am accessing one of the instrument through LAN. I have defined it's IP address manually so I can access it. But I want to change it's IP address though LAN. I think if I get the MAC address of the instrument without giving IP address so I can do it. I have VI which gives MAC address when input IP address. I don't wanna give IP address. I wanna find instrument from MAC address on LAN.

    LabVIEW does not have lowlevel access to network functions.
    You could use system exec to do a ping sweep of the subnet followed by an arp table listing (arp -a), then parse the resulting output.
    If the device supports it, you can then change its IP remotely address via arp -s.
    Still, I don't quite see the need for all that. Can you explain why you need this?
    LabVIEW Champion . Do more with less code and in less time .

  • I have a Mac Pro using OSX 10.7.4.  When using apple mail I click on the address icon to obtain email address and nothing happens.  I've restarted both the application and the Mac but still won't open address book.  Any ideas please.

    I have a Mac Pro using OSX 10.7.4.  When using apple mail I click on the address icon to obtain email address and nothing happens.  I've restarted both the application and the Mac but still won't open address book.  Any ideas please.

    Assuming you have these accounts set up in Mail, open preferences and under Accounts tab, edit the SMTP outgoing server list. Do you have a .mac address in the list? If so, delete it.
    Are you using iCloud?
    For the troubled account, select the correct SMTP server for that account in the box and check the box to use only that server with that account.

  • Should I use a MAC address to validate users for my program?

    I'm writing a graphical console program and I was planning on using a few methods for security. One being to block a user from logging in again if they don't type the correct username and password within three tries until the root user authenticates it again. I was planning on blocking the IP address but someone suggested blocking the MAC address since no 2 have the same ID and it's burned in, not to mention alot of people have dynamic addresses. However, I was reading that MAC addresses are mainly used in ethernet cards. I thought any device that has network capabilities has to have a MAC address? Is it good to use a MAC address for blocking someone from logging in again or what?

    Its very easy to change your MAC address. If you have a wireless router (which you can buy for like 20 dollars) then you can tell it what MAC address to use. So I agree, don't use a MAC address to block users from your program. Also are you sending the username/password over the network in clear text? If so, these can be intercepted. So doing that may be a bad idea; it depends on how much security you want for your application.

  • Obtain IP address from Mac address

    Hi all,
    Is ARD capable of obtaining IP addresses from mac addresses?
    Please advise.

    ARD's System Overview can display IP addresses and MAC addresses for computers it manages. If you're asking whether ARD can scan a network for a particular MAC address and return the IP address for a computer that's not in ARD's list of managed computers, then no, it can't (at least not by any method I know of). ARD is really not a network scanning/management application; it's for managing Mac workstations.
    Message was edited by: Dave Sawyer

  • Obtaining client's MAC address

    Is it possible to obtain the MAC address of a client connecting to my server socket?

    hi,
    well i figured out how to get the MAC address in Win 9x and Win NT 4.0, well i could not figure out the c/c++ api for doing a JNI call, but the next best thing is to run the native utilities and then get them to write to a output file,.. so for eg, you create a batch file like this
    runwin9x.bat
    @echo off
    winipcfg /all /batch mac.txt
    you then then use the Runtime.exec to get to run this batch file, it will create a file by name mac.txt , you then parse this file for the line containing the literal stirng "Physical address", A typical line looks like this..
    Physical Address.........: 00....
    if the number starts with a 44 instead, then it is the PPP Dial up adapter address, so just parse for the Line which contains the String physical address but does not contain the number starting with 44-...
    For winNt you can use the winmsd.exe to get it to write to a file..
    for eg
    runwint.bat
    @echo off
    winmsd /s/f
    now the gotcha is that this creates a file with the machine name.. in the format machinename.txt..., you then parse this file for a line containing the String
    "Transport.."..
    well what you could do, is first figure out the OS by doing a System.getProperty("os.name") , then call the respective batch file [using Runtime.exec], parse the batch file outputs depending on the OS and then get the MAC address... and after getting the address, just delete the output file resulting from running the batch file...
    I dont know the c/c++ call for this.. i someone could point out which library to use, it would be useful..
    cheerz
    ynkrish

  • [Z97 XPOWER AC] Eeupdate.exe program to write back the MAC address into the BIOS

    Hi,
    Following the procedure of restoring a fully corrupted bios in a Z97 XPOWER AC, now I need the tool to write the MAC address back to the chipset.
    Anyone of you has the latest version of Eeupdate.exe that can be used for it?
    Many thanks.

    use this one https://www.dropbox.com/s/mrxtkw1bdpudh50/Eeupdate.rar?dl=0

  • I need to change the MAC Address for Airport on MacBook

    I have a specific need to change my son's Airport MAC address as his school requires the use of USB network cards that aren't compatible with MACs. These cards are needed because the school's router uses MAC address filtering.
    Before we upgraded his Mac to Snow Leopard, we were able to change the MAC address to the MAC address of the useless dongal the school supplied. We basically created an AppleScript program that ran the "sudo ifconfig en1 ether xx:xx:xx:xx:xx:xx" and all was good.
    This command no longer works for changing the MAC address. We tried it as root user as well and by typing it into the terminal window as root. After running the command, we can run "ifconfig en1" and it does display the new mac address but when we turn the airport on and try to connect, it just hangs and won't connect.
    Our other non-Snow Leopard still works fine after running the commands so I'm guessing Apple disabled this functionality. It's hardly a security issue by being able to change your mac addres.
    Is there a new way to accomplish this? I've searched everywhere.
    Thanks!

    Would an easier solution be to provide the school's IT admin with your mac address and have it added? If they can add a block of mac addresses for the usb dongles, they can add more for machines that cannot use the dongle.
    Also: "It's hardly a security issue by being able to change your mac address."
    While it may not be a security issue for your machine, it is a security for the school network who is using mac address filtering as hopefully only one part of their wireless security.
    That being said, have you read this?
    http://osxdaily.com/2008/01/17/how-to-spoof-your-mac-address-in-mac-os-x/

  • Ethernet MAC address has changed and I can no longer connect to the network

    I have a new iMac, 21.5" running 10.6.4. It was purchased in the past month.
    I am using it on an ethernet network and using DHCP to obtain the address. It has been working for the past few weeks. I turned it on today and it is failing to connect. After some digging around, it seems that the MAC address (Ethernet ID) has been reset to 00:10:18:00:00:00. This is different to the one it has been using last week.
    I have not changed any network settings. Airport is working fine.
    If I pull out the ethernet cable and reinsert, the machine tries to obtain an IP address. After a while, it returns with a self-assigned IP Address.
    Last week, I did notice that it was taking a relatively long time (a minute or so) to obtain the IP address over ethernet. Plugging the same ethernet cable in a macbook, I am able to obtain the IP address for the macbook much more quickly.
    I see that I could use ipconfig to change the interface address to what I believe is the correct address. Would this be sensible?
    Why would the machine have reset the MAC address anyway?
    Regards,
    Neil

    Dear all,
    I am having the same problem with a new MacBook Pro, bought end of October - for me it became apparent for software (Matlab, Comsol) that are registered with a licence file which was created based on the MAC address, and also when trying to register the computer to the company network. That software will only work those times that the computer "knows" its real MAC. Also, I found that audible audio books, managed through itunes, will not synchronize with the ipod at those times when the MAC address is at the producer's default (00:10:15:00:00). I never had network issues other than this computer registration, - no probs at home or elsewhere - , so it will depend on the individual setup which issue users observe.
    I have had long phone discussions with different Apple support people, they have done checks based on Capture Data that I sent to them via email, etc.. They can't find the problem in the software/setup and they advised me to go the Genius Bar and have those guys look at the computer's guts.
    Restarting sometimes did set the MAC to the real one, also running the code that someone suggested in Terminal sometimes helped.
    Other than that, looking through the web, it does not seem to be an Apple-unique problem, but certainly one would like to see support to take care of that issue for Macs soon.
    Also, thanks a lot for this thread! Otherwise the support guys on the phone would not have believed my : "the Mac address changes on a daily basis" and would just have brushed me off.
    All the best,
    Susanne
    Message was edited by: semperula

  • :smileymad: 8520, MAC installation Problem= .MAC Addresses no longer exist, folks!

    Hi, when I intalled the software ot interface my BB with my MAC Pro it screwed everything up. In order to organize everything it asks me for my .MAC address, something which hasn't existed for years. I I can't even use one of the enw MAC addresses bacause the ".MAC" part of the address is hard-written into the form!
    Also, it is now opening Entourage, instead mf my MAIL program. I have absolutely no use for this if it ins't part of a larger interface which permits me to coordinate my calendars...
    How can I at least get back to zero, and preferable take advantage of the features I bought this stupid phone for?

    Well, quite honesly, I don't believe Entourage is on the BlackBerry CD provided with the device. So I still don't know what all is going on.
    ON your BlackBerry disc, you might have installed PocketMac?
    I would recommend UNinstalling it if you did, and instead download and install a more recent version from here:
    https://www.blackberry.com/Downloads/entry.do?code=A8BAA56554F96369AB93E4F3BB068C22
    Entourage is akin to MS Outlook, only for the Mac. And, Entourage is a product of Microsoft as well. For issues with Entourage, I would contact or look for the Entourage user forums.
    Sometime this month, rumored soon, BlackBerry will introduce it's Mac-compatible Desktop Manager application. From what I have read and heard, you will be pleased with it.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Sync Mac Address Book - multiple Google accounts

    I hope this is the right place for this question.
    I understand that you can sync the Mac Address Book with Google accounts, but is there a way to sync that Mac Address Book with MULTIPLE Google accounts.
    Our scenario is that we have one iMac as our main database, and want to sync it to mine, and my wifes Google account.
    Thanks for any help.

    I have found a program called Spanning Sync
    http://spanningsync.com/
    It allows for multiple Google syncing

  • Windows 7-8.1 Can not change the MAC Address on wifi and cannot load login page in public HotSpot.

    Windows 7-8.1 Can not change the MAC Address on wifi and cannot load login page in public HotSpot.
    Adapter: Ralink RT3070 Chipset wifi adapter
    Tested: os Windows 8.1 Professional
    Hot Spot: 802.11b
    The first problem windows 7-8.1 got IP adress and connect he public HotSpot  but  cannot load login page or any other page. It does not work with it.
    The second problem Wifi canrd/configure/Advandes (No network adress change function).Tested with the default windows driver and the ralink rt 3070 driver the same problem.On windows XP the same function the same driver works perfectly.
    multiple users to have expressed interest in the problem But Microsoft not corrected the problem window7-8.1 10?
    lizardsystems.com/wiki/change_mac_address/faq/change_mac_address_in_windows_7
    blog.technitium.com/2011/05/tmac-issue-with-wireless-network.html
    superuser.com/questions/519189/how-to-change-the-mac-address-in-win-8-to-spoof-a-roku-player-through-a-wifi-spl
    social.technet.microsoft.com/Forums/windows/en-US/59e07df3-471c-499e-ad5f-e7cb507595df/cannot-change-mac-address-in-windows-7-driver-has-option-doesnt-work-neither-does-regedit-ms?forum=w7itpronetworking
    networksteve.com/windows/topic.php/CANNOT_CHANGE_WIRELESS_%28SPOOF%29_MAC_ADDRESS_ON_WINDOWS_7/?TopicId=16810&Posts=1
    On windows XP or linux have a MAC adress Change function  allow 00 mac adress and another normal mac adress range.On windows 8.1 all Mac changer program dont work.This 2,6,A,E on second adress are not vaild Mac adress. You simply can not use normal MAC
    addresses on windows 8.1.When i connect the usb the Pc windows 8.1 recognizes the adapter but the default  driver and the downloaded ralink driver the same problem.On windows xp the current driver works perfectly have (Local Mac Network Adress) funktion
    and works with the 802.11b hot spot.I got the internet my PC and laptop too public HotSpots and another wifi HotSpots if wont work correctly i can not use neither the windows 7,8,8.1 or 10. Many users have expressed interest in the problem more forums.
    The 3. problem im tested in virtualbox the windows 7 and 8.1 on 8.1 (on the blue wifi platform) not show correctly the signal strengh. On windows 7 show this correctly.The windows 7-8.1 Configure/advanced the advanced options on Ralink 3070 the default (windows
    driver) somehow downgraded function is less than for Xp. Configure/advanced the advanced options (needs to be upgraded in the future) because it does not advance but rather regressed.
    Today it is very common these wi-fi technology increasingly used (hotels,Public Hots Spots,Internet coffe,) growing free bublic wifi projects. The wifi funktions on windows  need debugging and modernize.The quality of Wi-Fi is now the operating system
    is now a thing order which is not good then the operating system is unusable.

    Hi,
    For changing the MAC address for Windows 7 is designed with some limitation, we cannot get over it. Thanks for your understanding.
    Under Windows 7, the possible range of spoofed addresses for wireless adapters that can be set is limited.  To be used by Windows 7, a spoofed MAC address should have 0 as a least significant bit (unicast) and 1 as a second least significant
    bit (locally administered) in the second nibble.  Thus possible values for the second nibble are limited to 2, 6, A and E.
    In other words 
    MAC address:  “XY-XX-XX-XX-XX-XX” “X” can be anything hexadecimal.  The hexadecimal “Y”, written in binary format, is  Y:  “kmnp”,  where “p” is the least significant bit; 
    p=0 --> unicast;
    p=1 --> multicast;
    n=0 --> globally assigned MAC;
    n=1 --> locally administered;
    So, actually MAC can be changed  to any combination in which p=0 and n=1;
    “Y” can be 2, 6, A or E.
    So the possible MAC addresses in Windows 7 for wireless adapters:
    X2-XX-XX-XX-XX-XX
    X6-XX-XX-XX-XX-XX
    XA-XX-XX-XX-XX-XX
    XE-XX-XX-XX-XX-XX
    For the wifi hotspot issue, please check this blog to see if it can be helpful.
    Windows 7 Connectivity Problems in Public Hotspots
    http://blogs.technet.com/b/patrickr/archive/2010/07/28/windows-7-connectivity-problems-in-public-hotspots.aspx
    Kate Li
    TechNet Community Support

Maybe you are looking for

  • Intermittent lock ups

    Any ideas as to why my computer locks up or freezes for a 10 seconds then it starts going again? What kind of clues should I be looking at?

  • How do I stop Quicktime loading the last 5 videos I have watched?

    Ive just updated to Lion and  If i watch several files using QT and use "command Q" to quit them , everytime I load another file it reloads all the previous flies I just watched. I know i can use the small red x in the top left hand corner and the wo

  • TS3212 can't install iTunes

    I can't install the iTune. It popup and said< "iTunes was not installed correctly. Please reinstall iTunesj Error 7 (Windows error 126). Then I followed the instruction and reinstall, but still can't work. What can I do?

  • Unicode issue for the INSERT statement...

    Hi, In ECC 6.0, the following INSERT statment give short dumps: FIELD-SYMBOLS:   <fs_tabname>   TYPE ANY."Dynamic table name DATA: t_bdi_entry  TYPE STANDARD TABLE OF bdi_entry, INSERT (<fs_tabname>) FROM TABLE t_bdi_entry. If any one know the reason

  • Cannot update / install java for OS X 2012 - 006 on 10.7.5

    after reinstalling/restoring from lion restore disk, on boot, system requests me to install java for OS X 2012 - 006 with automatic download failed : after downloading the install file from downloads archive I got also bad response : I did also try t