0

This probably has a very obvious answer, but what is the common way to get the router/gateway IP address of the packet I just received in pcap.net?

I know how to get the IP address source:

       packet.Ethernet.IpV4.Source.ToString()

I tried looking through the object browser, but I didn't find a property that seemed to match. Any way I could find it?

Kat
  • 2,460
  • 2
  • 36
  • 70

1 Answers1

1

It's more of networking question, than programming one. A short answer would be - You can't.

The source IP address will always (unless strangely translated by the gateway) belong to the endpoint You wanted to connect with. This way Your application will get the response to any request You send. Unless You're using NAT the router does not alter the packet in any way so it's transparent from a connectivity point of view. The source address of the packet You just got would almost always contain the IP address of the server You connected to. That's the way Ethernet works.

A poor man's solution would be to use traceroute to find out which way the packets go and therefore get the address of the router, which generally would be the first hop along the way. From a programmer's perspective this would mean sending out several packets to the destination You got the packet from, each time incrementing the packet's TTL (starting from 1) and looking at the ICMP responses. This however could mislead You if some sort of load balancing is being done.

Maybe if You clarified what You would like to achieve I could point You in a better direction.

doubleud
  • 314
  • 1
  • 5
  • Well thank You for saying that, but my direction is really simple. I have a device that sends out a packet saying "here I am!". I wanted to know what router it came from without having to go through HTTP requests from the device to see what router it thinks its assigned to. But, if it cannot be done, that's okay. – Kat Jul 29 '14 at 14:15
  • Still not a straightforward answer, because I don't know the whole network You have, but You could possibly use Ethernet (MAC) addresses to get to know through which router the packet went. Every ethernet network device stores a mapping between the gateway's IP address and MAC address. It's the ARP table. You could try to add this information to the packet's payload, since the packet's lower layers would not be able to reveal that. Don't know if this sort of solution would be of any use to You though. – doubleud Jul 29 '14 at 14:43