Little router experiment

BlitzMax Forums/BlitzMax Programming/Little router experiment

BlitzSupport(Posted 2010) [#1]
I've been thinking about the problem of identifying a computer's public IP address when connected via a router, without using external web sites to determine what it is.

I connect via a mobile broadband USB adapter, so can't try this for myself, but the HostIPs function returns a list of all IP addresses for the named computer, and theoretically that named computer could be the router connected to the internet.

In theory, the underlying commands (gethostbyname, etc) are implemented by most network devices, so I'm wondering if a router would respond with its own list of IPs, including the public IP, as a named Windows PC does when sharing its connection (at least in a non-Blitz version of this program I wrote).

So, if you connect to the internet via a router which is set as your PC's default gateway, as most would be, please can you try this out:

1) From a command line, run ipconfig;
2) Copy the Default Gateway address for the adapter to which your router is connected (often starts with 192.168.x.x);
3) Paste it at the top of the code below, in h$, and run it. (As it stands, it should just list all IPs allocated to your local PC.)


' NB. You may have to allow this through your firewall!

' Insert Default Gateway from cmd -> ipconfig here:

h$ = "127.0.0.1"

Print ""
Print "Host: " + HostName (HostIp (h$))
Print ""

Local ips [] = HostIps (HostName (HostIp (h$)))

For ip:Int = EachIn ips
	Print DottedIP (ip)
Next

Print ""
Print "Public IP:"
Print ""

net = ReadFile ("http::www.hi-toro.com/ip.php")

If net
	Print ReadLine (net)
	CloseFile net
EndIf


Some questions:

1) Does it list multiple IPs for your router, or none at all?
2) If any IPs are returned, do any of them match the listed public IP address?
3) Router make/model if known.

I don't expect it to work for every setup -- if any at all -- but I'm curious and can't try it for myself! It may just fail on trying to convert the router's IP to a hostname, dunno.

Thanks to anyone who tries. (I probably won't see any responses until tomorrow.)


jsp(Posted 2010) [#2]
It lists my own Lan and VPN IP of my PC.
No match to my public address.

In theory, the underlying commands (gethostbyname, etc) are implemented by most network devices, so I'm wondering if a router would respond with its own list of IPs, including the public IP, as a named Windows PC does when sharing its connection (at least in a non-Blitz version of this program I wrote).

But it does run on the computer not the router?? Am I missing here something.


GfK(Posted 2010) [#3]
I get:
Host: mygateway1.ar7

10.1.1.1

Public IP:

[IP edited by BlitzSupport]
Its a D-Link DSL-G604T running Australian firmware.


Kurator(Posted 2010) [#4]
I get:


Host: notebook

192.168.0.6
192.168.56.1

Public IP:

[IP edited by BlitzSupport]



0.6 is the local ip for the wlan
56.1 is the local ip for the "virtual box host only network" adapter


xlsior(Posted 2010) [#5]
I get:


Host:

192.168.1.2
192.168.0.1
192.168.249.1

Public IP:

71.<snip>



(There's some virtual adapters/netblocks for VMWare Workstation in the mix, hence the multiple 192.x addresses)


In theory, the underlying commands (gethostbyname, etc) are implemented by most network devices, so I'm wondering if a router would respond with its own list of IPs, including the public IP



I seriously doubt it, since one of the purposes of most home-use routers like the linksys/dlink/etc. is to seperate your local network from the big bad internet. For typical operation, there normally is no reason for any PC on the LAN to have to worry about what happens or exists on the WAN side of the connection.
If anything it would advertise the LAN info, and keep the WAN info (which includes the public IP) hidden from the LAN clients.


degac(Posted 2010) [#6]

Host:

192.168.1.140
192.168.56.1

Public IP:

87.xx.xx.xx



Tested on my computer connected via wireless to a Netgear station, connected to a ADSL modem...


BlitzSupport(Posted 2010) [#7]
Thanks all -- it doesn't work then!


slenkar(Posted 2010) [#8]
network programming is so annoying


jsp(Posted 2010) [#9]
IIRC UPnP could do the trick, but not every router supports that.