Dear All, how can I get the private ip of client system from a website hosted on public ip in ASP.Net C#? while i am checking userhostname, it's showing the global IP of the Internet connectivity which is the same for all the machines in the network. Please advice me. 开发者_JAVA百科
Thanks in Advance
Anoop George Thomas
Short answer is no, not from the server side. You may be able to write client-side code that looks up the system's actual IP address, though you may need to do it by way of a browser plugin.
A better question is "Why do you need do to that?" Generally, if you have to have the internal IP, you are doing something wrong.
Unfortunately, it's not something you'll be able to pull.
Now, you can grab an IP of a machine that's coming through a proxy or other some such forwarding device. Here's an example function that utilizes the HTTP_CLIENT_IP and the HTTP_X_FORWARDED_FOR IP if they are available in your server environment.
<?php
function getIP(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
echo getIP();
?>
精彩评论