0

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.

Surya
  • 79
  • 1
  • 11
  • 2
    `PING www.google.com (74.125.228.115) 56(84) bytes of data.` – Jeff Lambert Jun 26 '14 at 14:37
  • I've tried that & got an IP while pinging but ping `request timed out`. Is that ok? Can I give them this IP address? I'm afraid, I can't go for them again & again asking to change IP. – Surya Jun 26 '14 at 14:42
  • See http://stackoverflow.com/questions/5800927/how-to-identify-server-ip-address-in-php – fdehanne Jun 26 '14 at 14:43
  • you can configure your server/routers/switches to ignore ICMP packets, which will effectively silently discard both pings and tracerts (and cause the client's request to time out). Some servers do this in an attempt to mitigate DOS attacks. – Jeff Lambert Jun 26 '14 at 14:43
  • I'm sorry, I didn't get you. Can you explain? – Surya Jun 26 '14 at 14:48
  • You can send a ping request to my server, but I can configure the router providing that server to ignore your ping request, which could be a reason why you get a request timeout. If DNS can't even resolve your hostname, you will get a different error – Jeff Lambert Jun 26 '14 at 14:57

3 Answers3

2

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");
?>
James Hunt
  • 2,448
  • 11
  • 23
  • I've tried that & got an IP while pinging but ping request timed out. Is that ok? Can I give them this IP address? I'm afraid, I can't go for them again & again asking to change IP – Surya Jun 26 '14 at 14:42
  • That is the most likely IP, if it timed out it might just be their firewall blocking ping requests. – James Hunt Jun 26 '14 at 14:49
  • Just to add a note, it doesn't sound like you are but if you happen to have your web site being served from behind a load balancer (ie, you actually have multiple servers running your site), then you will have multiple IPs that you will need to identify and send over. – Jeff Lambert Jun 26 '14 at 14:56
  • @JamesHunt I've tried that too (also, mentioned in the question). This always returns a single IP but I don't know how do they verify my IP. If this is how they do it,it will be fine. If they use some other methods, my ip address will not be a static one. – Surya Jun 26 '14 at 15:05
  • (I do apologise, didn't see the "from another server" part) Why not give them the one it returned and email them explaining how you got it and if it is right? If you ask meaningful questions they will hardly belittle you for it! – James Hunt Jun 26 '14 at 20:36
0

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

GuCier
  • 6,919
  • 1
  • 29
  • 36
  • I got `request timed out`. What does that mean? – Surya Jun 26 '14 at 14:49
  • Maybe the provider is not responding to ping, which is surprising! I updated with a pure php version, could you try it? – GuCier Jun 26 '14 at 14:50
  • this `gethostbyname()` gives me different IPs as I've already mentioned in the question. – Surya Jun 26 '14 at 14:51
  • If you use it with `google.com` you will have a different result depending on your geographic position : Google have many servers. If the ip is wrong, check if you are calling the function with a host like `sub.domain.com` and not like `http://sub.domain.com/` – GuCier Jun 26 '14 at 14:58
  • So, this is the problem, I guess. I use Appfog.com & they use AWS which has many servers over the world. So, I'm getting different IPs for different pings. If this is yes, can you tell me a workaround, please? – Surya Jun 26 '14 at 15:06
-1

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

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

user3669523
  • 69
  • 2
  • 3
  • 11
  • `'REMOTE_ADDR' The IP address from which the user is viewing the current page.` OP wants IP of his web host, not the user. – Jeff Lambert Jun 26 '14 at 14:40