Solved

Show Proxy IP or Real IP

Posted on 2004-10-11
13
1,253 Views
Last Modified: 2007-12-19
hello there,
i want to show in php that if im using a proxy
---------
Proxy IP: 81.26.35.62
Host: 81-26-35-62.speedyterra.com
Your Real IP Is: 24.157.108.253
Your Real Host Is: adsl-24-27-108.isp.com
---------

but if i am not using a proxy just
---------
Your Real IP Is: 24.157.108.253
Your Real Host Is: adsl-24-27-108-.mia.isp.com
---------

this is what i have

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$raddr = trim(getEnv("REMOTE_ADDR")); if (getenv("HTTP_X_FORWARDED_FOR")!="")
$raddr = getenv("HTTP_X_FORWARDED_FOR"); if (getenv("HTTP_CLIENT_IP")!="")
$raddr = getenv("HTTP_CLIENT_IP");
$realhost = gethostbyaddr($raddr);

echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
echo "Your Real IP Is: $raddr<BR>";
echo "Your Real Host Is: $realhost<BR>";
?>
0
Comment
Question by:Xtry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12281328
add a condition around the first two echos:

if (getenv("HTTP_X_FORWARDED_FOR") || (getenv("HTTP_CLIENT_IP") ) {
echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
}

echo "Your Real IP Is: $raddr<BR>";
echo "Your Real Host Is: $realhost<BR>";
0
 
LVL 2

Expert Comment

by:hewtluca
ID: 12281867
Try this:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
 if ($_GET['HTTP_X_FORWARDED_FOR'] || $_GET['HTTP_CLIENT_IP']) {
$raddr = $_GET['HTTP_X_FORWARDED_FOR'] ;
$raddr = $_GET['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $ip <BR>";
             echo "Host: $realhost";
} else{

$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>

Regards
0
 

Author Comment

by:Xtry
ID: 12286920
Hello there
Thanks for all replies,, hewtluca your code is working but if i am using a proxy or my real ip
It shows me your real ip is 81.35.65.32 both ways
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 2

Expert Comment

by:hewtluca
ID: 12287131
Opps try this:

<?php

 if ($_GET['HTTP_X_FORWARDED_FOR']) {
$raddr= $_GET['HTTP_X_FORWARDED_FOR']  || ;
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
}elseif ($_GET['HTTP_CLIENT_IP']){
$raddr  = $_GET['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
} else{
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>
Regards
0
 
LVL 2

Expert Comment

by:hewtluca
ID: 12287142
Dag I must be half asleep, this should work, scratch my last post.

<?php

 if ($_GET['HTTP_X_FORWARDED_FOR']) {
$raddr= $_GET['HTTP_X_FORWARDED_FOR'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
}elseif ($_GET['HTTP_CLIENT_IP']){
$raddr  = $_GET['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
} else{
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>
Regards
0
 

Author Comment

by:Xtry
ID: 12287192
hehehe np man.
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 200 total points
ID: 12287228
hewtluca have you verified that the HTTP_X_FORWARDED_FOR is defined in the superglobal $_GET ? It is typical only located in $_ENV or via getenv()

This should give you the output you wanted:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
$raddr = trim(getEnv("REMOTE_ADDR")); if (getenv("HTTP_X_FORWARDED_FOR")!="")
$raddr = getenv("HTTP_X_FORWARDED_FOR"); if (getenv("HTTP_CLIENT_IP")!="")
$raddr = getenv("HTTP_CLIENT_IP");
$realhost = gethostbyaddr($raddr);

if (getenv("HTTP_X_FORWARDED_FOR") || (getenv("HTTP_CLIENT_IP") ) {
echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
}

echo "Your Real IP Is: $raddr<BR>";
echo "Your Real Host Is: $realhost<BR>";
0
 

Author Comment

by:Xtry
ID: 12287243
Your Real IP Is: $raddr
Your Real Host Is: $realhost
Proxy IP: $ip
Host: $fullhost
0
 

Author Comment

by:Xtry
ID: 12287271
thanks hernst42,
using proxy only thing i see is

Your Real IP Is:
Your Real Host Is:
0
 
LVL 2

Accepted Solution

by:
hewtluca earned 300 total points
ID: 12287336
I told you I was half a sleep :)  Try this.  I am not actually verifiying these, because I should know them.

<?php

 if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
$raddr= $_SERVER['HTTP_X_FORWARDED_FOR'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
}elseif ($_SERVER['HTTP_CLIENT_IP']){
$raddr  = $_SERVER['HTTP_CLIENT_IP'];
$realhost = gethostbyaddr($raddr);
             echo "Proxy IP: $raddr <BR>";
             echo "Host: $realhost";
} else{
$ip = $_SERVER['REMOTE_ADDR'];
$fullhost = gethostbyaddr($ip);
              echo "Your Real IP Is: $ip<BR>";
              echo "Your Real Host Is:  $fullhost";
}
?>
Regards
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12287364
If you only get those two line then the proxy your are using does not forward that information. You might add the following to get more infromation:

if (getenv("HTTP_X_FORWARDED_FOR") || (getenv("HTTP_CLIENT_IP") ) {
echo "Proxy IP: $ip <BR>";
echo "Host: $fullhost<BR>";
} else {
    var_dump($_ENV);
}

Perhaps in the dump you see your real IP adress and in which variable it is stored.
0
 

Author Comment

by:Xtry
ID: 12287876
thank you guys
0
 

Author Comment

by:Xtry
ID: 12287880
i got all the information i needed!
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question