Solved

Show Proxy IP or Real IP

Posted on 2004-10-11
13
1,230 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
  • 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now