I need to find out my web hosting server's IP address. Its on a shared hosting server and from experience, it's usually not the same as the incoming IP address that you would get by just pinging the domain name. Is there a php script I can run or something to find our the outbound IP address my website is using when connecting to a SMTP server for example?
4 Answers
I have success when I try
curl -s ip.appspot.com
Or with PHP:
<?php
echo file_get_contents("http://ip.appspot.com");
?>
You could do a web request from code (PHP or other) and request a URL such as www.whatismyip.com and save it as a file that you open and look at.
Reading Remote URL HTML Source in PHP shows some examples. If your PHP installation allows for it, then this could be as simple as creating a file with the following, and then point your browser to it:
<?php
// See http://www.whatismyip.com/automation for the exact URL
echo file_get_contents(
"http://www.whatismyip.com/automation/n09230945.asp");
?>
-
2See also whatismyip.com/automation which currently refers to whatismyip.com/automation/n09230945.asp for use in scripts.– ArjanNov 28, 2010 at 12:47
-
Awesome answer, but that URL (whatismyip.com/automation) doesn't work anymore. Why not just leave it as
http://www.whatismyip.com
? Then you'll see the same page you would see if you navigated there in your browser, except with the server's IP instead of yours. Oct 22, 2013 at 16:24
The host server outbound IP address is the one you see when you ping it, regardless of whether the shared host is name or IP based.
For name based shared hosts (all websites share the same IP), the user agent will add the hostname to its requests, which will allow the server to determine which website to show.
For IP based shared hosts (each website has its own IP), name resolution is straightforward.
If you are looking instead for the internal IP address used by your server in its network, this information can be accessed by connecting to your server through a secure shell, which most web hosts provide.