Page 1 of 1

Display IP address using PHP

Posted: Sat Aug 24, 2002 7:32 am
by digger69
Hello people,

I am wondering if somebody can help me out with a little code snippet..

I want to make up a quick web page to diplay the Ip address (mine) negotiated between my dialup server and the computer that has dialed it up.

The reason for this is multiplayer gaming (Ghost Recon :D :lol: ). Because the IP address is dynamicly assigned when they dialup it cant be given out before hand and needs to be generated on the spot.

If anybody can help me out on this it would be apprieciated.

I am not sure what category this type of script would belong to so if you could simply advise on that matter I can do the rest

This is my first time on this forum so if this is not the place for this type of question... my apologies

many thanks...... New Newbie esquire :wink:

Posted: Sat Aug 24, 2002 9:40 am
by volka
maybe gethostbyname() is helpful

BUT:
hmmm...how do they open the html/php-page without knowing the IP or net-name of your PC? ;)

probably the dialup client's default gateway IP is the one of the server.
for win9x/etc there's a programm called winipcfg (?)
for w2k/etc type "ipconfig" in the commandline

in both cases there should be something like "PPP-Adapter [...] default gateway: w.x.y.z"

edit: sorry, once again I didn't get the point of the question
you (as server) dialed up and the others (as clients) dialed up, too :(
but
hmmm...how do they open the html/php-page without knowing the IP or net-name of your PC? ;)
still stands
You might consider using a dynamic dns entry service like http://www.dyndns.org/
If I'm in the mood (to run DeeEnEs.exe as my dyndns-client) you can ping my PC with "ping kernschmelze.dyndns.org" (atm: 217.225.12.245 ;) )

Posted: Sat Aug 24, 2002 10:30 am
by digger69
Yep sorry Volkan,
I'm not real flash at getting my piont across clearly, so here is the full senario....

I am using Win 98, dial-up server on my machine.
I have created an entry page on my server (Apache, PHP4) That is availble at

http:yeah/gr (Intranet only)

So my mates dial-up my machine, and enter http:yeah/gr in thier browser and get taken throu to the page.

Here is the tricky part.....

They need to know the IP adress of my dial-up adapter so it can be entered into the MP game screen, however as you Know, until they actually dial my server my local IP adress is 127.0.0.1, which changes as soon as they dial in.

winipcfg lets ME know the newly negotiated IP adress but with out editing the web page every time we want to play I have no way of letting the bloke at the other end know what the Ip address is.

If there is a simple PHP script that I could insert into the entry page to display my currant Ip address it would be a lot easier.

I am not familiar with PHP scripting. I do use the phakt Dreamweaver UD extension to generate PHP scripts to query Mysql databases, with a high degree of sucess... (yes I can sense the shudder of PHP coders upon reading that :D )

PHP, Phakt, Mysql, Phpmyadmin, Dreamweavern UD are a truly awesome team whereby, a humble boilermaker/welder, such as my self can aspire to dot com greatness :lol: .

The game bit is simply an unhealthy distraction I could, reluctantly, probably do without.

Thanks Al.....

Posted: Sat Aug 24, 2002 11:37 am
by volka
maybe this works

Code: Select all

<html><body>
<?php 
$servername = 'yeah';
	$arr = gethostbynamel($servername);
	print('<table border="1"><tr><th>my IPs</th></tr>');
	foreach($arr as $ip)
		print("<tr><td>$ip</td></tr>");
	print('</table>');
?>
</body></html>
but they still can use winipcfg to determine their default gateway for the PPP-Adapter after they dialed in. It should be the IP of your maschine.
Windows 2000-IP-Konfiguration
[...]
Ethernetadapter "LAN-Verbindung":
[...]
PPP-Adapter "T-DSL":
[...]
Standardgateway . . . . . . . . . : 217.225.12.245
Standardgateway <-> default gateway, that's the machine that handles my Inet traffic atm. In case of dial in to a private network this should be the IP of the server-interface.

A simple ping from the clients to your machine should do, too. Use the net-bios name for it (ping yeah). Since the name can be resolved when used in the browser it can be resolved for ping, too ;)

Ghost recon isn't able to resolve names in the connect string?
something like connect to:"yeah:2346" (2346 is the default port number for the server, isn't it? )

Posted: Sat Aug 24, 2002 11:44 am
by digger69
Thanks Volka..... I didn't give you a head ache did I :lol:



<?php echo getenv("SERVER_ADDR"); ?>

This little gem did the trick.

Maybe what I was on about is clear now. :lol:

Thanks for making the effort

"Arl b Bark"
Arnie, mid 80's

Posted: Sat Aug 24, 2002 11:49 am
by volka
hmmm....that evals on my machine to nothing :?:

Posted: Sat Aug 24, 2002 11:53 am
by digger69
This is the full code.
Tried your code, definatley much prettier :wink:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p>
<?php echo getenv("SERVER_ADDR"); ?>
</p>
</body>
</html>

Posted: Sat Aug 24, 2002 12:22 pm
by volka
and I found getenv("SERVER_ADDR");
It's not set for my apache module and/or php version ;)

Posted: Sat Aug 24, 2002 1:55 pm
by daemorhedron
For php 4.1.0 and higher, you can easily do this in one line in your file :

<?=$_SERVER['REMOTE_ADDR']?>

That's it. =)

HTH

Posted: Sat Aug 24, 2002 2:01 pm
by volka
then he would display the IP of the requesting client
but he wants to display his own IP (a bit being his own DNS-Service ;) )