Possible Duplicate:
Linux / C++: Get the IP Address of local computer
I am trying to get my local computer's IP and MAC addresses of all interfaces, but I can not really succeed. I need to get it together, so I know which IP belongs to which MAC.
I went through a lot of searching on google and even here, but I can not really find a C code for this.
Could you please help me?
Thanks in advance! I would really appreciate that!
Here is how you can check it: On an unaffected host on the same network, open up a command prompt. On a Windows machine, type "arp -a [suspected duplicate IP]" and hit enter. On a Mac or Linux machine, type "arp [suspected duplicate IP]" and hit enter.
To do so, you need to open a Command Prompt window and enter the command “arp -a”. That way you will get all of the IP addresses that are active on your network. You will get a list with the physical address, which is the MAC address and the corresponding IP address.
To see all the MAC addresses and their associated IP addresses, type “arp -a”. This command will list all the available MAC addresses in the system. The address on the left is the IP address, while the right is the MAC address.
Manufacturers re-use MAC Addresses and they ship cards with duplicate addresses to different parts of the United States or the world so that there is only a very small chance two computers with network cards with the same MAC Address will end up on the same network.
On relatively recent versions of Linux, you can just read the contents of /sys/class/net/eth0/address
(substituting any network interface name for eth0
) to get the hardware address of an interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With