简体   繁体   中英

Private IP of client machine from website

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.

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();

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM