How could I convert from IP address to MAC address - c++

I want to store all the MAC the mac address which has access to my server.
All I know are only the IP addresses. All the machines are under unique gateway.
Could I got the MAC address from their IP address?

MAC addresses are not part of any protocol that gets routed, you will never get the MAC address of a machine that is on the other side of a router or switch.
They are are the addresses of the physical ports, not of machines (which are what you're taling to using IP).

If server and client are on the same network, you will have to use ARP. This protocol is designed to get the MAC address to a given IP address.
As soon as there is something like a router between client and server, ARP will only reveal the MAC address of the router since this is the target for your ethernet packets.

Simple answer is, no You Cannot get MAC Address from an IP Address for clients connecting to your server unless both the machines are on same Physical network

It is not possible to get MAC address from IP address. MAC address is a physical address of network device, and IP address is not.
IP address is not bound to one device in general.

I suggest you go through this
the post says
An IP address is usually assigned by the network administrator or internet
service provider, you are either provided a static one at the beginning or
given a dynamic one every time you connect to the network.
This is not true with MAC addresses as it is already embedded on the device
or the network card during manufacturing. It is supposed to be permanent and could
not be changed by anyone as it was meant to identify a specific network interface
card no matter where it is in the world.
There are however ways to change mac addess, but i don't think it is possible to get mac address using IP- Address

Related

IP address and MAC address used in DPDK

Hello Stackoverflow experts,
I have been struggling with how to use the ip fragmentation provided by DPDK. and was wondering I have the correct concept of IP address and the MAC address used in rte-mbuf ethernet header.
Is Ip address alone in the header of rte-mbuf can be used to transfer from local to remote?
I see in the DPDK sample applications that the ip address is used in the hashed tables such as IP fragment table after the packets are received, but the fact that data is actually received just by using ethernet mac address, gives me the impression that IP address is only defined by the DPDK user (developers using DPDK API) and not used in actual data transfer.
Is there something missing to what I understand?
You are right. Most DPDK examples work on the second level of the OSI model, i.e. they only care about MAC addresses, not IP.
The IP reassembly example is based on L2 forwarding example, i.e. it acts as an Ethernet bridge. Though, it requires IP addresses to be analyzed, i.e. source and destination IPs must match for all the fragments of the same flow.
Now answering your questions:
Is Ip address alone in the header of rte-mbuf can be used to transfer from local to remote?
If you mean transfer using rte_eth_tx_burst() then no, IP header is not enough. The ethernet header must be filled properly as well.
IP address is only defined by the DPDK user (developers using DPDK API) and not used in actual data transfer.
Since the reassembly example is based on L2 forwarding example, it acts as reassembling Ethernet bridge. So you have a right impression, this example does not route packets based on IP addresses. It just uses IP addresses to reassemble IP fragments.

How to get IP adress with WINSOCK ? c++

I'm not familiar with networks and etc so I dont get how to use it, so if anyone can help me how to get ip adress of my computer with it and I also have to get MAC adress too.
WinSock is a Windows-specific API. Most socket APIs in general do not provide information about local IP/MAC addresses. You might be able to use getaddrinfo() to query the IP addresses for localhost, but that would be implementation-specific whether it works or not, and it would not include MAC addresses anyway.
On Windows, the correct way to get the IP and MAC addresses for the local machine is to use GetAdaptersInfo() or GetAdaptersAddresses() to enumerate the local NICs.
On POSIX-based platforms, including OSX, you can use getifaddrs() to get the local IP addresses (family AF_INET/6) and MAC addresses (family AF_LINK).

How to get Mac Address from WAN IP?

I'm using SendARP() to get mac address form an IP.
But this function only work correctly with LAN IP.
If I have many devices in other LAN network, they will have the same WAN IP (ex: 219.123.111.90), but their ports are different.
So if I call the function SendARP("219.123.111.90:80") or SendARP("219.123.111.90:81")..., it will return only one Mac Address.
I think the SendARP only get the Mac Address of the Modem without getting real devices on that LAN network.
Please show me how to get the real mac address of devices that belong to other LAN network?
Many thanks,
T&T

Detecting IP addresses of network cards and ethernet devices with Windows API

I am using the Microsoft code here to learn how to detect IP addresses of cards and devices:
http://msdn.microsoft.com/en-us/library/aa365949%28v=VS.85%29.aspx
I notice some strange behavior.
I have a system with two ethernet cards; one is connected to the internet and one is connected to an ethernet device. When I run the sample code, it will always give an IP address for the card that has the internet connection, but the other card will come up as 127.0.0.1 with a subnet mask of 255.0.0.0 unless I have the ethernet device plugged in and powered. But the card should have a default IP address whether its actually connected to anything, right? How can I modify this code to detect that?
There's a third IP address detected that appears to be just empty data. I tried this on another computer with a single network connection and it also detected a second, non-existent connection. Each time, this connection has an IP address of 127.0.0.1 and a subnet mask of 255.0.0.0. What does this represent?
Given the demo code, would this be easy to edit to be able to detect IP addresses of devices on the network that any card is connected to? I really just want to detect the IP address that a single ethernet device is set to. The device is directly connected to the card. The reason I want to do this is because the device and card obviously don't play nice when their subnets are different and I want to detect when this is the case.
Thanks!
R
That address of 127.0.0.1 is not the address of the other card. It is the address of the loopback adapter - a virtual IP address that can only send and receive data with itself. The other NIC (that isn't plugged into a network) is simply not in the address table.
You may just want to call GetAdapterAddresses and filter out all adapters with an IFType of IF_TYPE_SOFTWARE_LOOPBACK.
If you want to see use existing tools that provide the same thing, type either of the following from a command prompt:
route print
(This will dump the routing table)
ipconfig /all
(this will show you the state of ALL adapters including the loopback)
Dunno exactly, you should at least specify your configuration, is it DHCP or static IP, or something else?
It's the loopback interface
Some broadcasting may be required. ARP is the link-layer protocol, so it can be used without the IP address to broadcast a link to find the devices and then to detect their address. Don't know about windows precisely, but on Unix an arping command is present for this.

A Reliable way to Identify a computer by its ip address

I have a network of computers that they will connect to the a server with DHCP, so I don't know what Ip address a computer will get when I connects to the server. If 192.168.0.39 for example is connected to the server can I identify the real computer behinde this ip address? ( I can install an external application on each client in order to send some data to server for example mac address or so... )
If you are responsible for the DHCP server, you can configure it to hand out a specific IP to a specific MAC. Having done that, you can be reasonably confident of that mapping -- it is possible to spoof MACs, so if you are worried about security, you'll need a much more heavy duty approach. If this is a casual application where the risk of that is low, you configure your DHCP server to hand out IPs based on MACs and then make use of those mappings in your application.
You might not even need the IP address. On an Ethernet network, all communication from a computer, whether it's IPv4, IPv6, or even IPX will be labelled with a MAC address that's stable over time and unique per network card.