Sockets

BlitzMax Forums/BlitzMax Programming/Sockets

Jeroen(Posted 2005) [#1]
Hi!

How can I retrieve my external IP address in Blitzmax? I found some posts on this, but this was before Mark released the socket library.

sock=CreateTCPSocket()
Print SocketRemoteIP(sock)


Nothing is returned. I assume I have to do a dottedIP$ in the end for sake of readability.


Tom(Posted 2005) [#2]
How about

http://www.tomspeed.com/myip.php
<?php
echo $_SERVER["REMOTE_ADDR"];
?>



marksibly(Posted 2005) [#3]
Hi,

As far as I know, there is no bullet-proof way to get your 'real/public/WAN' IP address without connecting to something else external that echoes it back to you, ala the PHP code above.

I would love to be proved wrong on this one though...


FlameDuck(Posted 2005) [#4]
I would love to be proved wrong on this one though...
Don't hold your breath. The problem is that NAT routers, invisible proxies and all manner of wonderful technology your ISP may be using, will pretty much ruin that. You could find the IP of the next link at the router after yours, but there's no guarantee that'll actually work.

You could use http://www.myip.dk and just parse the output from that.


Jeroen(Posted 2005) [#5]
Okay thanks! I had used the PHP solution already, but I was wondering how games like Quake and Half-Life do this when you connect to a multiplayer game.

Another question: what is the best way to get the LAN address (not WAN)?


Leiden(Posted 2005) [#6]
mIRC somehow finds out the external IP address even though Im behind both a hardware firewall (nForce one) and the Windows XP firewall plus a NAT server on another computer somehwhere else in the house).

Using something similar to GNet would it be possible to set up some kind of External IP finding thing on BlitzBasic which echo's the IP back to the computer using port 80 or something (http port). Not exactly a ideal solution but It would sort of work.


xlsior(Posted 2005) [#7]
mIRC somehow finds out the external IP address even though Im behind both a hardware firewall (nForce one) and the Windows XP firewall plus a NAT server on another computer somehwhere else in the house).


That's probably because mirc connects you to a remote server, which in return will be able to see and report your IP back to you.

If you are running a server locally, it wouldn't be able to see its own remote IP without querying some remote server either.


Leiden(Posted 2005) [#8]
Isnt the external IP address of a computer stored somewhere in the registry? I remember a while back a utility that found my external IP address from a registry file, this of course, would only work if you had a dailup or fixed ip connection to the internet, if your behind a router then your probably screwed like FlameDuck mentioned.


TomToad(Posted 2005) [#9]
You could go to http://www.whatismyip.com/ to get your IP. Not sure how to do this in Blitz except to maybe have the program parse the web page and extract the IP, but I'd think you'd need permission from the web host to do that.


Tom(Posted 2005) [#10]
That's what my PHP example above does TomToad :)

For obvious reasons though, I wouldn't rely on any 3rd party 'get-my-ip' resources.


Panno(Posted 2005) [#11]
http://www.blitzforum.de/viewtopic.php?t=13284 ?


xlsior(Posted 2005) [#12]
Isnt the external IP address of a computer stored somewhere in the registry? I remember a while back a utility that found my external IP address from a registry file, this of course, would only work if you had a dailup or fixed ip connection to the internet, if your behind a router then your probably screwed like FlameDuck mentioned.


Exactly -- and those routers are *very* common nowadays, with the large # of people using DSL or cable connection... If there's a router involved, the PC has no way of finding out what the external IP is other than bounce it of a remote server and ask what it thinks the source address is.


Leiden(Posted 2005) [#13]
@xlsior: even then sometimes you cant be certain as alot of ISP's have their own weird ways of handling high speed connection IP hand outs. A friend from school has a high speed connection, he cant host games unless he contacts the ISP and tells them he's hosting on port blah blah. His external IP comes up the same as the ISP's DNS servers IP. Very weird.


Mr G(Posted 2005) [#14]
You could try creating a STUN client, although I wouldn't know how myself!

http://www.ietf.org/rfc/rfc3489.txt

http://en.wikipedia.org/wiki/STUN


xlsior(Posted 2005) [#15]
@xlsior: even then sometimes you cant be certain as alot of ISP's have their own weird ways of handling high speed connection IP hand outs. A friend from school has a high speed connection, he cant host games unless he contacts the ISP and tells them he's hosting on port blah blah. His external IP comes up the same as the ISP's DNS servers IP. Very weird.


Sounds like they're running everything through a firewall on their end then... Probably a fairly small outfit, it would become unmanagable really fast.


Filax(Posted 2007) [#16]
Another method, i hope that usefull...