Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get local IP and MAC address C [duplicate]

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!

like image 575
shaggy Avatar asked Jul 20 '11 19:07

shaggy


People also ask

How do I find duplicate IP addresses?

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.

How do I find my IP address and MAC address on the same command?

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.

How do I get a list of IP addresses and MAC addresses?

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.

Can MAC addresses duplicate?

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.


1 Answers

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.

like image 93
bitbucket Avatar answered Sep 30 '22 16:09

bitbucket