The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: nrdev on June 15, 2009, 02:33:24 PM

Title: Getting IP number from the system
Post by: nrdev on June 15, 2009, 02:33:24 PM
I'am confused I have found many functions that are related to the IP, but I don't know witch one I should use to get IP from the system.

What function should I use for this?
Title: Re: Getting IP number from the system
Post by: Slugsnack on June 15, 2009, 03:56:08 PM
do you want public or private IP ?
Title: Re: Getting IP number from the system
Post by: nrdev on June 15, 2009, 06:04:07 PM
You see I don't know witch is witch, I want my program to get the IP from the system. As far as I know IP have the same layout for servers and for normal PCs.
Title: Re: Getting IP number from the system
Post by: ecube on June 15, 2009, 06:40:37 PM
well private address is the address no one remotely can access, for instance your loopback address which is 127.0.0.1/localhost. Routers have internal addresses that are usually 192.168.*.*. So to access my router for instance it's http://192.168.0.1. To get your remote ip the easiest way is to  connect to whatismyipaddress.com or similar and parse the return(some give only the ip address no other data so its easy). You can also setup a php on a remote server and have your program visit it

;test.php

$v_ip = $_SERVER['REMOTE_ADDR'];
if (strstr($v_ip, ', ')) {
   $ips = explode(', ', $v_ip);
   $v_ip = $ips[0];

echo $v_ip;


windows wininet functions are easy to use to visit and grab the IP. Another method if you use a router is to connect via UPNP functions and grab it from there, but thats alil more tricky. You can loop through network cards on the system to get their interal ip address, quite a few examples of that on here and madwizard.
Title: Re: Getting IP number from the system
Post by: nrdev on June 15, 2009, 09:11:59 PM
I have found this functions in masm32.inc, but I don't know how to use them, can someone, show me an example of usage of this functions?

IPtoString      PROTO :DWORD,:DWORD
GetIP           PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
Title: Re: Getting IP number from the system
Post by: dedndave on June 15, 2009, 09:52:40 PM
you are looking at the protos
masm32\m32lib\getip.asm
Title: Re: Getting IP number from the system
Post by: nrdev on June 15, 2009, 10:49:40 PM
ok, I can get IP, but I can't make it appear correctly in the DlgIPAddress. How can I solve this problem, I have converted my ip to string with IPtoString function.