How to get IP of my site, exactly?

225 Views Asked by At

I've contacted some website administrators for their API, in return, they have asked for source IP, in order to whitelist it, so that only requests from that IP will be considered as legit (it is ok even if it is a shared IP).

So, now the problem is how do i get the ip of the site. Being a PHP developer, I've tried gethostbyname() which gives random ip's & also $_SERVER['REMOTE_ADDR'] (called from other server) which always gives the single IP. I'm totally confused with this, also I've very less time to give them my source IP.

I don't have paid hosting. I always use, free tiers of appfog (*.aws.af.cm) & openshift (*-name.rhcloud.com). It would be great if someone can tell me the process for finding any of those IP addresses or show me a way to get a static IP (which i could share with them) for free or another host. Also, they have given permission to use this API only for 10days.

UPDATE: I've also tried ping mysite.aws.af.cm (which is same as gethostbyname()) gives different IPs for different calls.

3

There are 3 best solutions below

5
James Hunt On

Web hosts usually have static IP addresses but I'm surprised they require an IP for a web-based API instead of a domain/some kind of secret key.

Have you considered just pinging your domain, as the ping command will convert your domain into the IP address it correspondes to?

EDIT: Another solution.

Considering your API is being contacted by the server, I have created a file on my own website that returns $_SERVER['REMOTE_ADDR'], BUT you should access the file using a script on your site!

Upload the following to your website and run it:

<?php
    echo file_get_contents("http://barathesh.com/server.php");
?>
1
user3669523 On

Use this php function and echo out the result like so:

$myip = ($_SERVER['REMOTE_ADDR']); echo $myip

5
GuCier On

From command-line

Ping it from your terminal (works in Windows & Linux based OS)

ping youhostname.com

will print something like

64 bytes from 74.125.206.100: icmp_seq=0 ttl=44 time=3.151 ms
64 bytes from 74.125.206.100: icmp_seq=1 ttl=44 time=3.116 ms

Pure PHP

Take a look to the gethostbyname function

echo gethostbyname('yourdomain.com');

will output the ip adress of yourdomain.com