MAC Address of other wifi device in a wifi network - c

Is it possible to find the MAC address of all other wifi enabled device in a wifi network programmatically by using C or C++, if so then please tell me the way or direction, how can i do that Visual Studio 2012.

If they are in same LAN next to your device (no router/switch in the middle, The scope of ARP is link-layer.) you should use sending ARP packets to devices.
Address Resolution Protocol (ARP) is a telecommunications protocol
used for resolution of network layer addresses into link layer
addresses.
To send ARPs you can use Pcap or SendARP.

Related

Send message using MAC address on PC without IP in LAN

Need to send messages on PC without configured IP using MAC address in C language as a reply on PC's broadcast message. I suppose I should work with ethernet-header and use some (linux) kernel's structures and subroutines, however I couldn't find good links and samples about my question.
Example of sending a raw Ethernet frame in Linux:
https://gist.github.com/austinmarton/1922600

determine mac address of switch port you are connected to

Is it possible to figure out what is the mac address of the switch port you are connected to?
I was looking in tcpdump, but it seems that in each ethernet packet the MAC of the sender and destination, but not of those MAC's it passing. But i'm looking for way to find out the MAC of the switch you are directly connected to.
I should be a generic solution. For example a managed CISCO switch, is not a solution (yet).
I have C/C++ at my disposal or any other language.
Read this:
http://en.wikipedia.org/wiki/Network_switch#Layer_1_.28Hubs_versus_higher-layer_switches.29
In a normal switch they don't have a MAC address. Unless what you are using is a bridge.
TCP/IP are above the switch in network layer abstractions. Specifically, they're at the Transport and Internet layers, respectively (Transport is above Internet). You need to inspect the raw Ethernet packet, for Link layer data.

How to get a TCP/IP packet over an serial connection (Bluetooth)

I'm developing an TCP/IP stack that will run on another device connected by bluetooth.
But I want to test against an working Stack. My testing scenario would be:
MY DEVICE TCP/IP STACK --------------BLUETOOTH ----------------- WINDOWS/MAC TCP/IP Stack.
Anyone have any idea how could I write IP packets over an Bluetooth connection on Linux/Windows or mac ??
One way is you could establish a ppp connection between the device and the PC over bluetooth first. For this you will need support for ppp on the device side. Once you are able to dial-up and establish a ppp connection, tcp/ip can be run over ppp.
These links may be useful (although they are specific to linux):
http://www.daybefore.net/bluetooth_ppp.html
http://www.rpgameplace.de/blog/index.php?/archives/19-Networking-over-Bluetooth-using-BlueZPPP.html

How can I extract mac address from a icmp reply in c on linux

I am trying to find out mac address of a machine in a switched environment after sending it a raw packet. I am trying to implement traceroute command . I want to know when i receive a ICMP time exceeded message how can I extract the mac address of that machine . I am a new to network programming so am confused what socket call will help me to extract the mac address.
Thanks .
No, you can not extract MAC address from ICMP reply.
You can only determine MAC addresses of linked machines next to you. In ICMP(tracert) you can just find out the IP address of target or middle machine.
If you want to detect MAC addresses, you should use ARP protcols where it's applicable in local networks not Internet.
ICMP protocol starts after IPv4 header[1] and MAC addresses is related to physical/link layer. In low level layers the MAC addresses will transparent from top level layers such as network(IP) or Transmission,...
To determining MAC addresses, you should use Raw sockets or PCAP SDKs to access lower layers of network programming. (I say again, these are not useful over Internet)
Like Masoud M said, you can only get the MAC address of machines that are on your local network. That said, you can parse the output the arp command to find the MAC address given the IP address of a machine one your local network.
In general, on internet, you don't even know the media a host is using for transmitting packets. Let's suppose a remote host is conected over a serial rs-232-C link with PPP protocol. It doesn't have a mac address. This also happens for example if the host uses a token ring interface or frame relay link. This makes determining the remote mac addresses of hosts a local issue completely. Normally, when you get a packet from a remote site over ethernet, the source mac addres you get in the packet is the one of the last router that links you to the internet, not the one of the original host that sent the IP packet. In the RFC on IP over avian carriers (rfc1149, rfc2549 and rfc6214) the media used for transmission doesn't allow to use mac addresses (the link address, if somewhat feasible on a pidgeon could be, would be its name)
If you want to read about traceroute on ethernet network of switches, perhaps you had to have a look at the IEEE802.1ag, that has an specification to do tracerouting over switches (tracelink service) but I think is far over the scope of this answer.

Programmatic use of ARP

I have a need for some C or C++ code, compilable under Linux, to be able to take a list of IP addresses of some arbitrary number of remote hosts machines and obtain a ethernet MAC address for each one. These host machines may be on the same subnet or they could be on a different subnet behind a router. Its OK if the MAC address of some or all of the remote hosts is the address of the interface on the router. Ultimately, I want to hand off the IP address and MAC address to an FPGA who will use these pieces of information to format and send UDP/IP packets over ethernet to the hosts. Obviously, the FPGA will also be given its own MAC address and IP address to fill in the source MAC and source IP addresses in the packets.
Is there some code I can be pointed to that can create and broadcast ARP packets to these remote machines and receive back the ARP response packets such that the destination MAC addresses can be extracted?
Part of what you want to do requires some raw socket programming.
http://mixter.void.ru/rawip.html
The source for the linux arp command will give the rest of what you need. Here's a link:
http://www.comp.nus.edu.sg/~cs4236/readings/out/html/arp_8c-source.html
I recommend looking into arping which is doing a somewhat identical job. It takes IPs and MACs and tries to receive additional informationen. Or justs pings them.
http://freshmeat.net/projects/arping/

Resources