I'm using PHP CURL to send a request to a server. What do I need to do so the response from server will include that server's IP address?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I think you should be able to get the IP address from the server with:
That will give you all the IP addresses associated with the given host name.
AFAIK you can not 'force' the server to send you his IP address in the response. Why not look it up directly? (Check this question/answers for how to do that from php)
I don't think there is a way to get that IP address directly from curl.
But something like this could do the trick :
First, do the curl request, and use
curl_getinfo
to get the "real" URL that has been fetched -- this is because the first URL can redirect to another one, and you want the final one :Then, use
parse_url
to extract the "host" part from that final URL :And, finally, use
gethostbyname
to get the IP address that correspond to that host :Well...
That's a solution ^^ It should work in most cases, I suppose -- though I'm not sure you would always get the "correct" result if there is some kind of load-balancing mecanism...
I used this one
from here: http://php.net/manual/en/function.gethostbynamel.php
This can be done with curl, with the advantage of having no other network traffic besides the curl request/response. DNS requests are made by curl to get the ip addresses, which can be found in the verbose report. So:
Demo: