HostOnNet Blog

Find Server Main IP

Looking for Linux Server Admin or WordPress Expert? We can help.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.