i'm running an hidden service as the final exam of my school, but i've a problem: i have to show that the IP of the same computer which connects to my website can change in a bit , but when i try functions such as $ip=$_SERVER['REMOTE_ADDR']; it always gives me 127.0.0.1 instead of the last tor node which connects to me.
How can i solve this ? Is it normal on the Tor network? Cheers in advance!
There is a no direct way , but you can try using a third party server to get actual ip even from localhost server.
<?php
$content = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $content, $ip);
echo $externalIp = $ip[1];
?>
Here is a working PHPFiddle . Hope this will help, cheers :)
Related
I'm using geoplugin php to get the country and ip of visitors on my site, but its returning the ip and country of hosting server instead of user who visit the site, I'm using Hostinger as my hosting.
$ipdat = #json_decode(file_get_contents("http://www.geoplugin.net/json.gp"));
$country = $ipdat->geoplugin_countryName;
$ip = $ipdat->geoplugin_request;
its working fine on xampp localhost.
Your code behavior is an expected behavior since the GEO plugin site gets the IP address from where the script request came and gives details accordingly. If you want user/visitor's data, then you will need to make use of user's remote IP stored in $_SERVER global variable and pass this IP to GEO plugin to get the details as mentioned in their docs.
Snippet:
<?php
$data = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']));
$country = $data['geoplugin_countryName'];
$ip = $data['geoplugin_request'];
echo $country," ",$ip,"<br/>";
print_r($data);
I am using software called gns3 to build networks.
I have the need to find out devices external ip from within an gns3 internal network. This would be like a pc behind a router doing NAT.
Please could someone tell me if there is a way that you can echo out the clients external ip in php so I can add a web server to one of my virtual networks within gns3 so I can visit it on some devices and find their external ip’s for testing?
Thanks in advance
You need to make a request to an external website that could tell you the ip address you have. You may use checkip.dyndns.org - click the link to see your own ip addres.
if you want to do that from php here is an example code:
<?php
//get website content as a string
$ipCheckUrl = 'http://checkip.dyndns.org';
$subject = file_get_contents($ipCheckUrl);
//extract from string just ip address
$pattern = '/Current IP Address\:\s*(\d+\.\d+\.\d+\.\d+)/U';
$ip = preg_match($pattern,$subject,$result) ? $result[1] : 'Error';
//print ip address.
echo $ip;
i m sorry im newbie here,.. so i want to ask about, how to get the IP from the server,.
.
first i user PEAR2 to get an api from Mikrotik, then i want to get an IP for making a log, to log what an IP that Connect or Dissconnect from the network itself... the reason why i make the log from PEAR2, i want to make a notification android based, that if the client from the mikrotik's is disconnect or connect, it will send a notif to an android apps..
.
in those case PHP i use this script,
echo $server_ip = gethostbyname($_SERVER['SERVER_NAME']);
?> is this a correct..?
.
many thanks for you all. im sorry for My bad English
You want echo $server_ip = $_SERVER['SERVER_ADDR']
What you have gives you the host name.
Like this for the server ip:
If you mean getting the user's IP address, you can do something like :
<?php
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else{
$ip=$_SERVER['REMOTE_ADDR'];
}
?>
<?php echo "<br />".$ip;?>
This question already has an answer here:
How to get server's public IP address using PHP?
(1 answer)
Closed 1 year ago.
I am connected to a lan.. I can access internet. using the browser I can find my public ip using the search "what is my ip".
I want to get the public ip using php
I am running the script in my localhost wamp server..
I tried:
$_SERVER['REMOTE_ADDR'] and $_SERVER['SERVER_ADDR']` both give me `localhost ip ::1
Is there any networking functions that can give me my public ip address?
is there any way without using any external service? because if I use an external service, it may not available in the future.
try this please:
$externalContent = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
$externalIp = $m[1];
Or use httpbin.org/ip as Priyesh Kumar suggests
You can use API to get public IP address from localhost.
https://www.ipify.org/
<?php
$ip = file_get_contents('https://api.ipify.org');
echo "My public IP address is: " . $ip;
?>
try this too and check with print_r
$ip= isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
Try this as it is tested on local machine(localhost)
$ip = file_get_contents('https://api.ipify.org'); echo $ip;
I Think you should use $_SERVER['REMOTE_ADDR'] to get the IP address of the router
How do I get something in PHP/Curl to grab the IP of the URL for me? It's going to be a simple interface that fetches URL IP's back for me.
E.g. Enter "http://mysite.com" then I hit submit then I should get the IP of the mysite.com back.
gethostbyname
$ip_string = gethostbyname( "stackoverflow.com" );
echo $ip_string; //returns ip address, ie 12.34.56.78
Try the gethostbyname function.