slpctrl Posted January 25, 2008 Share Posted January 25, 2008 How would I go about getting the traceroute results from an IP and writing them to a log? I'm trying to write an IP logger, and I'd like for it to log their location too but I can't quite figure it out. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/87843-php-traceroute/ Share on other sites More sharing options...
slpctrl Posted January 25, 2008 Author Share Posted January 25, 2008 Actually, here's the code for the whole thing I've got so far. It works, that's not the problem. I want it to write the location too: <?php function clean ($var) { return htmlspecialchars($var); } $ip = clean($_SERVER['REMOTE_ADDR']); $entry = "<b>IP:</b> $ip<br /> \r\n"; $fp = fopen('iplog.html', "a") or die('Cannot open logfile'); fwrite($fp, $entry); fclose($fp); ###OUTPUT IMAGE### $file = "imagesource.gif"; $fp = fopen($file, "r") or die('Cannot grab image source'); $content = fread($fp, filesize($file)); header("Content-type: image/gif"); echo $content; fclose($fp); ?> Now, this is a .gif ip logger for use on forums and things. So don't really worry about the output image, I put the inside of a .gif file, and wrote this to .htaccess: AddHandler application/x-httpd-php .gif So that my server will handle .gif files as .php. Then I added imagesource.gif but none of that really matters, I need location ??? Quote Link to comment https://forums.phpfreaks.com/topic/87843-php-traceroute/#findComment-449358 Share on other sites More sharing options...
resago Posted January 25, 2008 Share Posted January 25, 2008 use a system call to tracert, you can put the results in a string or array. look at exec should be easy, as long as your script has enough rights. Quote Link to comment https://forums.phpfreaks.com/topic/87843-php-traceroute/#findComment-449360 Share on other sites More sharing options...
slpctrl Posted January 25, 2008 Author Share Posted January 25, 2008 use a system call to tracert, you can put the results in a string or array. look at exec should be easy, as long as your script has enough rights. I'm hosting it locally. Now, my tracert command (I know, I could use passthru() ) But, it doesn't give me the location, here's an example of what I might come up with: Tracing route to www.phpfreaks.com over a maximum of 30 hops: 1 8 ms 7 ms 6 ms 10.42.192.1 2 19 ms 10 ms 8 ms srp3-0.dytnoh1-rtr2.woh.rr.com [24.29.160.7] 3 22 ms 21 ms 27 ms network-024-095-081-217.columbus.rr.com [24.95.8 1.217] 4 27 ms 30 ms 27 ms ae-3-0.cr0.dca20.tbone.rr.com [66.109.6.70] 5 28 ms 28 ms 28 ms ae-1-0.pr0.dca10.tbone.rr.com [66.109.6.165] 6 33 ms 27 ms 27 ms 64.132.69.61 7 59 ms 61 ms 61 ms 64.128.245.106 8 59 ms 59 ms 59 ms 64.128.245.106 9 61 ms 60 ms 65 ms 204.8.178.42 10 69 ms 62 ms 61 ms 204-13-168-167.reverse.serverpowered.net [204.13 .168.167] 11 58 ms 62 ms 66 ms 66-97-171-5.reverse.serverpowered.net [66.97.171 .5] Trace complete. So no system commands really return a location :-\ Quote Link to comment https://forums.phpfreaks.com/topic/87843-php-traceroute/#findComment-449368 Share on other sites More sharing options...
slpctrl Posted January 26, 2008 Author Share Posted January 26, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/87843-php-traceroute/#findComment-449404 Share on other sites More sharing options...
resago Posted January 26, 2008 Share Posted January 26, 2008 you could capture a whois and get an address from that. Quote Link to comment https://forums.phpfreaks.com/topic/87843-php-traceroute/#findComment-449436 Share on other sites More sharing options...
hitman6003 Posted January 26, 2008 Share Posted January 26, 2008 If you have the ip address you can use something like the geoIP location data from maxmind...it's a csv (that should be imported to a database) that you can use to determine a location based on IP. http://www.maxmind.com/app/geolitecity Quote Link to comment https://forums.phpfreaks.com/topic/87843-php-traceroute/#findComment-449438 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.