# html post ip on webpage



## jackdw (Jul 1, 2005)

I run a small server for me and my friends. It usually runs counter strike.

Problem:
I have a dynamic IP and the router disconnects a lot.

I have a no-ip account and I was wondering, if I ran a webserver on the server and people went to my URL, is there a way some code could display the server's external IP address so they know what the IP is of the server to join?

I hope I make sense
Thanks
Jack


----------



## Duckman69 (Jun 26, 2007)

so your saying the ip they need to connect on is based on your ip because the server for whatever is a program that bases that info off your ip and other info... so if your ip changes so does there server address, and you want them to be able to check it to see what its current address is from now on?... i hope i understood that part right... also i dont think you can do that i may be wrong though ... no way to get that ip to stay manual & locked as is? then just post the ip info of the set ip after that...


----------



## jackdw (Jul 1, 2005)

That's exactly what I want duckman.
I know people can ping the no-ip address in cmd but some people aren't that computer proficient, and it's a pain.


----------



## Duckman69 (Jun 26, 2007)

alright, no way to set a perment ip for your pc then? how does that ping no-ip thing work i mean if you have a dynamic ip and its always changing hows that work im unfimiliar with this a bit myself... if you can do it threw command tho theres probally a web command as well, maby some1 else on the forums will know of it...


----------



## namenotfound (Apr 30, 2005)

If your site runs PHP, you can do this:


```
<?php echo $_SERVER['SERVER_ADDR']; ?>
```
That will tell you the IP address of the server.


----------



## jackdw (Jul 1, 2005)

Duckman. no-ip is a server (noip.com) that offers URL's for people who have a dynamic IP address (ie, IP changed every time a connection is made) a way to find their IP address anywhere.
Mine, for instance is jackdw.no-ip.info and if you were to type that into remote desktop connection, you will be faced with the login screen to my server. noip replaces the need to remember an IP or have to worry about the router disconnecting and issuing a different IP address when you are running a website or wanting to access your PC via remote desktop.

Namenotfound, the site doesn't exist yet but I will install a php/mysql webserver (apache). What do I do with that code?


----------



## namenotfound (Apr 30, 2005)

jackdw said:


> Namenotfound, the site doesn't exist yet but I will install a php/mysql webserver (apache). What do I do with that code?


Just put it in the page, make sure the page has a .php file extension. For example "mypage.php" instead of "mypage.html"

It will work as soon as you paste it in. Just paste it where you want it to show up, where ever you put it, on the page you'll see *xxx.xxx.xxx.xxx* (but with actual numbers, that's the IP address for the server)


----------



## jackdw (Jul 1, 2005)

Problem:
I just tried it on a webserver I have access to and it shows it's internal 192.168 address rather than the external IP...


----------



## Squashman (Apr 4, 2003)

jackdw said:


> That's exactly what I want duckman.
> I know people can ping the no-ip address in cmd but some people aren't that computer proficient, and it's a pain.


Then create a batch file or VBscript for them to run to ping your Domain Name and return the IP address.

And I guess I am kind of confused on why they need the IP address to connect to your server. What is wrong with just using the domain name. Kind of the whole point of DNS.


----------



## Duckman69 (Jun 26, 2007)

thanks for the info jack i kinda new 1/2 that but was confused on some of it appreciate it


----------



## MMJ (Oct 15, 2006)

jackdw said:


> Problem:
> I just tried it on a webserver I have access to and it shows it's internal 192.168 address rather than the external IP...


When I go to *http://jackdw.no-ip.info* it prompts my for the login information of your router.


----------



## jackdw (Jul 1, 2005)

MMJ, that would be because I am yet to forward port 80 to the server as I am still setting up the game server with a friend. If you were to try it in remote desktop when the server is on, you will get a login screen because port 3389 is forwarded.

Squashman, for some reason I don't think the program that connects the games (steam valve) accepts anything other than numbers and dots in the IP address box. I may be wrong and I cannot test it myself as I am on the same network and have to connect by using 192.168.x.x


----------



## namenotfound (Apr 30, 2005)

jackdw said:


> Problem:
> I just tried it on a webserver I have access to and it shows it's internal 192.168 address rather than the external IP...


The IP is internal because you didn't set the server up to be accessed from an outside source yet. I'm assuming that's what it is.


----------



## jackdw (Jul 1, 2005)

The server I tried it on has a load of ports forwarded to it.
80
21
3389
2800
2900

Surely port 80 would make it display the external IP...


----------



## tomdkat (May 6, 2006)

jackdw said:


> The server I tried it on has a load of ports forwarded to it.
> 80
> 21
> 3389
> ...


Port forwarding won't do the trick. I'm with Squashman on this. Using the domain name is the key. So, maybe using PHP to do a DNS lookup on jackdw.no-ip.info will return an IP address that can then be posted on the webpage?

EDIT: Looks like using the PHP function dns_get_record() will do the trick.

Peace...


----------



## jackdw (Jul 1, 2005)

Looks like it tomdkat. How do I put that on a webpage? I did it here on my other server and it shows this:
http://whiting.no-ip.info/tdsq/thing.php


----------



## tomdkat (May 6, 2006)

You will need to write some PHP code to get the DNS record and then get the IP address from the array that's returned. The dns_get_record() function is a PHP 5 function that apparently has been backported to PHP 4. What version of PHP are you running?

Peace...


----------



## jackdw (Jul 1, 2005)

I have no idea which PHP I am running. All I know is that it's Wamp 5 http/mysql server. I can update it if it would help.
Is there anywhere I can get the code as I am 100% clueless about PHP!


----------



## namenotfound (Apr 30, 2005)

jackdw said:


> I have no idea which PHP I am running.


phpinfo() will tell you all about the php installation, including which version of php was installed.


----------



## jackdw (Jul 1, 2005)

It's phpmyadmin 2.9.0.3 if that's what your looking for.
namenotfound, I have no idea what to do with that, sorry.


----------



## tomdkat (May 6, 2006)

I think if you put this PHP code in a sample webpage, you can get the PHP version info:


```
<?php phpinfo(); ?>
```
 Save that line in a file called "phpinfo.php" and put in where your index.html file is. Then, load that php file in your browser (e.g. http://jackdw.no-ip.info/phpinfo.php) and the PHP version information should appear.

Peace...


----------



## namenotfound (Apr 30, 2005)

```
<?php
phpinfo();
?>
```
Save that (just that) as, say "info.php" or whatever you wanna call it.
Upload it to your site, then access it from yoursite.com/info.php and it will tell you all about your php installation

edit: tomdkat beat me too it


----------



## jackdw (Jul 1, 2005)

Well I installed wamp server on the server I want to use and the newest download of wamp includes PHP5.
With this PHP 5, this:

```
<?php
$result = dns_get_record("jackdw.no-ip.info");
print_r($result);
?>
```
Brings this error:
Fatal error: Call to undefined function dns_get_record() in C:\wamp\www\index.php on line 2

The server is at jackdw.no-ip.info with port 80 forwarded but I don't know if the router has applied it yet, it's a bit slow when it comes to ports...

EDIT: That above is the entire contents of index.php and nothing else. I know nothing about php so there's no extras, just that in the file.


----------



## Big-K (Nov 22, 2003)

if you wanted to use the function you'd have to actually install it.

if all you want is to print the ip address of your server you should be able to just put <?php echo $_SERVER['SERVER_ADDR']; ?> in the place where you want it to be(as long as its a .php file), that should print the ip address of the server that the script is running from, yours.


----------



## tomdkat (May 6, 2006)

namenotfound said:


> ```
> <?php
> phpinfo();
> ?>
> ...


I was just thinking, "_is there an echo in here_?" 

Peace...


----------



## tomdkat (May 6, 2006)

Big-K said:


> if you wanted to use the function you'd have to actually install it.


The dns_get_record() function is part of the PHP5 networking functions.
I just did a source build of PHP 5.2.3 on Linux and I just ran the script posted above. I got this back:

```
Array ( [0] => Array ( [host] => jackdw.no-ip.info [type] => A [ip] => 86.135.98.47 [class] => IN [ttl] => 60 ) )
```
I just re-read the doc for dns_get_record() and it has this note:


PHP5 doc said:


> Note: This function is not implemented on Windows platforms, nor does it (currently) work on *BSD systems (including Mac). Try the » PEAR class » Net_DNS.


So, I'll see what "Net_DNS" is.

Peace...


----------



## Squashman (Apr 4, 2003)

These might be an option for you.
http://www.info-techs.com/sshipup.shtml
http://www.elegantlogic.com/KeepMePosted/


----------



## Squashman (Apr 4, 2003)

Take a look at this thread on another forum as well. They got alot of creative ideas.
http://www.governmentsecurity.org/forum/index.php?showtopic=7686

Here is another old utility.
http://www.naughter.com/dynip.html


----------



## jackdw (Jul 1, 2005)

Squashman, that last link seems the best bet. Nice and simple. Do you know if it's compatible with Win XP?


----------



## Squashman (Apr 4, 2003)

I think the problem with the last link will be if it is compatible with your router.
I would think that KeepMePosted would be a better option. The SSHIPUP utility is just more security minded.


----------



## jackdw (Jul 1, 2005)

At second thoughts it seems basically the same so I'll give keepmeposted a go.


----------

