News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

get remote ip?

Started by ecube, October 18, 2007, 03:06:45 AM

Previous topic - Next topic

ecube

any programmic way to geta systems remote ip without visting a whatsmyip kind of website? Am creating a information program and this would be a handy feature. If anyones worried about malware or anything of that nature you can pm me, I highly despise such none sense. Thanks

u

Use GetAdaptersInfo(). Always like that:


local AdInfo[8]:IP_ADAPTER_INFO, dwBufLen
mov dwBufLen,IP_ADAPTER_INFO*8
invoke GetAdaptersInfo,addr AdInfo,addr dwBufLen
test eax,eax
jnz _Failed

Then filter-out 192.168.x.x and 127.0.x.x addresses .

Please use a smaller graphic in your signature.

Tedd

Just to confuse you even more..

0.x.x.x
10.x.x.x
14.x.x.x
127.x.x.x
128.0.x.x
169.254.x.x
172.16-31.x.x
191.255.x.x
192.0.0.x
192.0.2.x
192.88.99.x
192.168.x.x
198.18-19.x.x
223.255.255.x
224-239.x.x.x
240-255.x.x.x
255.255.255.255


..are all reserved; though you're unlikely to encounter most of them.


You can do gethostname followed by gethostbyname which will get you the local ip address. However, in the presence of a router (meaning you're on a LAN - your ip address will usually be 192.168.x.x) that's not what you want. The address you actually want to get is that of the router, which may be a little more difficult without getting some external site to tell you what it sees (unless there's a standard mechanism to ask the router what its ip address is.)
Apparently you should use GetAdaptersAddresses http://msdn2.microsoft.com/en-us/library/aa365915.aspx in preference to GetAdaptersInfo, though it's XP+ only. Not sure that it will manage to get you the external ip address though, but it's worth testing :wink
No snowflake in an avalanche feels responsible.

u

How about opening a pipe and running "tracert google.com"  :) . This way getting the whole array of routers, and filtering-out the first few that match the above pattern (192.168.x.x, and so on)
Please use a smaller graphic in your signature.

ecube

awesome tedd! you're a rockstar :D if you're on a router you can use upnp on xp+ to get your remote ip, most router companies support upnp technology. If you aren't on a router maybe getsockname on a connected socket will return your real ip, returns my router ip atm.