Ok, I use apache web server to host a club website within a school network. Now I need a script to display the ip address of my web sever because it is constantly changing. Is there scrip that will perform this function.

note: the site only works within the school network and can not be acssesed out side of our network so it is the subnet i[p that i need displayed.
tankyou

I don't think you can do what you want with only JavaScript, but it should be relatively easy if you can put a script on the web server and execute an external command. Then you can call that script's page with a JavaScript XMLHttpRequest (AJAX) request to get the IP address.

On Linux or Unix systems, the external command to execute is dig <servername> +short , but there are other commands you can parse the output of to get the same information.

On Windows systems, I think you can get the information you need by parsing the output of ipconfig , but I think you can only use that to get the IP address of the computer it's run on, not another one.

This short PHP script run on a Linux Apache server will simply output the IP address of the server named 'home':

<?php
$output = popen( "dig home +short", "r" );
$ip = trim(fgets($output));
pclose($output);
echo $ip
?>

The +short command line argument makes dig only output the IP address. If you want to use ipconfig or some other command, you'll probably have to parse the output of the command.

--
-- Ghodmode

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.