Shop OBEX P1 Docs P2 Docs Learn Events
How to get IP address of remote computer ? — Parallax Forums

How to get IP address of remote computer ?

BeanBean Posts: 8,129
edited 2011-09-08 00:24 in Accessories
I'm working with the "Brilldea W5100 TCP Server Echo Demo indirect Ver. 00.1" and I just want to print the IP address of the remote computer.

I wait until ETHERNET.SocketTCPestablished(0) is true, then I print the values in DestIP[], but they are always zeros ???

Any ideas how to get the IP address of the remote computer that connected ? I want to keep of log of them.

Bean

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2011-09-07 15:38
    Bean,

    Hmmm seems like I've seen that information being passed as part of the header hash... I ended up stripping it off. If you don't get a reply by this weekend, I'll look into it, but I think the information your looking for is already in front of you.
  • Mike GMike G Posts: 2,702
    edited 2011-09-07 15:39
    Bean, do you want the IP of the current socket request?

    id is the socket ID.
    PRI GetClientIP(id) | reg
    
      reg := (id * $100) + $400 + $0C
      ''readIND(_register, _dataPtr, _Numbytes)  
      Socket.readIND(reg, @clientIp, 4)
      
    return
    
  • BeanBean Posts: 8,129
    edited 2011-09-07 15:56
    Mike G, Thanks. That does get the IP of the remote computer.
    Problem is that it always returns my domain IP address. I guess the router handles the transmission to the actual dest IP address.
    Do you know if there is anyway to get the actual dest IP address ? Or is that only known by the router ?

    Bean
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-09-07 16:20
    AFAIK, once you encounter a router that does masquerading or port forwarding, the addresses routed to by those procedures are known only to the router and, in fact, won't be world-unique IP addresses anyway. For example, there are probably millions of 192.168.0.1 IP addresses out there.

    -Phil
  • Mike GMike G Posts: 2,702
    edited 2011-09-07 16:43
    Bean, that is the client IP making the request. I just hit the Spinneret from my web server and the IP of my web server was logged. Give me a second and I'll wire up a test web for ya.
  • Mike GMike G Posts: 2,702
    edited 2011-09-07 17:27
    Here's a TCP connection test page. Just put your URL in the text box and click the button. The client request should be coming from 65.98.8.151.

    http://www.agaverobotics.com/spinneret/tcptest.aspx

    Edit: just to make sure I'm no the same page. You should see my WAN address not my PC IP address If I hit your Spinneret.
  • BeanBean Posts: 8,129
    edited 2011-09-07 17:50
    Mike, I get an "Invalid URI" error when I enter "pebasic.com" (without the quotes).

    But I tried one of the proxy websites and it worked (it did NOT give me my local router address). So I'm good.

    Bean
  • Mike GMike G Posts: 2,702
    edited 2011-09-07 18:01
    Sorry, you need the full URL including http://
  • BeanBean Posts: 8,129
    edited 2011-09-07 18:07
    Mike, I got:
    Dest IP Address=65.98.8.130
    Dest MAC address=00:26:62:33:B1:90

    So I got 130 for the last value not 151 that you posted ???

    Bean
  • Mike GMike G Posts: 2,702
    edited 2011-09-07 18:17
    You're right! I assumed that a paid for unique IP would be unique as a server and a client. Obviously, I assumed wrong. I'm not much of a network guy.
  • BeanBean Posts: 8,129
    edited 2011-09-07 18:19
    Is the MAC address right ?

    This will be great for providing access to a spinneret ONLY to certain IP addresses or certain MAC addresses... Cool...

    Bean
  • Mike GMike G Posts: 2,702
    edited 2011-09-07 18:29
    Is the MAC address right ?

    I'm not sure. I can't get the MAC info from my hosting control panel.
  • TorTor Posts: 2,010
    edited 2011-09-08 00:24
    Bean wrote: »
    Is the MAC address right ?
    That's extremely unlikely. The IP address will be the remote address, but the MAC will be the MAC address of the first router.

    The way it works is like this:
    1: Computer A wants to talk to computer B.
    2: Computer A calls DNS to ask 'what is the IP address of B?'
    3: The name server replies that the IP address of B is '111.222.111.150'
    4: Computer A checks its own routing table to see if 111.222.111.150 can be served from the local subnet
    5: If no, then it'll go by a router, or gateway, say '192.168.1.1'
    6: Computer A does an ARP broadcast and asks 'What is the MAC of 192.168.1.1?'
    7: It receives the MAC address
    8: It sends the data (now we're on Ethernet level) to that MAC address
    9: The 192.168.1.1 router continues the same way, and asks for the MAC of the next gateway, and so on. But from then on that's invisible to computer A, it's all between the routers/gateways along the route.

    So the MAC address will always be of the nearest router.
    Even if your setup is such that there doesn't seem to be any routers in between (you can only manage this on your local network) then there could still be some computer in between (with a totally different IP address) which will respond to an ARP broadcast with 'Hey, I can serve that IP, here's my MAC'. It will then get that data, and forward it (maybe through another interface) to another computer.

    It's all because the IP address is an identifier on the IP (as in TCP/IP or UDP/IP) level, and identifies the end-to-end points, while MAC is an identifier on the underlying protocol (Ethernet), which identifies the point-to-point physical nodes.

    -Tor
Sign In or Register to comment.