Anoop George Thomas
Anoop George Thomas

Reputation: 41

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

Upvotes: 1

Views: 1434

Answers (2)

jerebear
jerebear

Reputation: 6655

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

?>

Upvotes: 2

Justin Morgan
Justin Morgan

Reputation: 2435

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.

Upvotes: 4

Related Questions