HostOnNet Blog

Find Server Main IP

Many IP scripts require you to white list your sever IP before you can use API.

On a server, there can be multiple IP address. But only main IP is used for out going traffic. So you need to find out the IP used by server.

You can do this with following small PHP script.

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.hostonnet.com/ip');
curl_exec($ch);

Save it as server-main-ip.php

Upload it to your web site, access it with

http://yourdomain.com/server-main-ip.php

You will get servers main IP. If your server have multiple IP, this can be different from the IP you get when you ping or nslookup your server.


Posted in PHP