/src/frontend/ipinfo.php

https://github.com/KaTaLyzer/KaTaLyzer · PHP · 64 lines · 55 code · 9 blank · 0 comment · 11 complexity · 7b447b0257dd3138e5a99d551bf032f4 MD5 · raw file

  1. <?php
  2. error_reporting(0);
  3. ini_set("display_errors", 0);
  4. Header("Pragma: no-cache");
  5. header('Cache-Control: no-cache, must-revalidate');
  6. Header("Expires: ".GMDate("D, d M Y H:i:s")." GMT");
  7. header('Content-type: application/json');
  8. session_start();
  9. define("INTERVAL", 86400);
  10. define("PAGE",25);
  11. require_once('inc/class_input.php');
  12. require_once('inc/class_config.php');
  13. require_once('inc/class_port_names.php');
  14. require_once('inc/class_ipinfo.php');
  15. if(isset($_GET['ip']) && preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $_GET['ip'])){
  16. $json['status']=true;
  17. $ip = $_GET['ip'];
  18. $input = new input('configs');
  19. $config = new config($input->config);
  20. $input->process_config($config->tree);
  21. $ipinfo = new ipinfo($config->host,$config->user,$config->pass,$config->database);
  22. $json['mac'] = $ipinfo->find_mac($ip);
  23. $json['dns'] = $ipinfo->find_dns($ip);
  24. if(isset($_GET['whois'])){
  25. exec('whois '.$ip,$whois_output,$whois_status);
  26. if(!$whois_status){
  27. $json['data'] = $whois_output;
  28. }
  29. }
  30. if(isset($_GET['nslookup'])){
  31. exec('nslookup '.$ip,$nslookup_output,$nslookup_status);
  32. if(!$nslookup_status){
  33. $json['data'] = $nslookup_output;
  34. }
  35. }
  36. if(isset($_GET['geoip'])){
  37. if(function_exists('geoip_record_by_name')){
  38. $location = @geoip_record_by_name($ip);
  39. if(is_array($location)){
  40. foreach($location as $k => $v){
  41. $json['data'][] = ucfirst(str_replace('_',' ',$k)).': '.$v;
  42. }
  43. }
  44. if(isset($location['latitude'],$location['longitude']) && is_numeric($location['latitude']) &&is_numeric($location['longitude']) ){
  45. $json['data'][] = '<br/><iframe width="724" scrolling="no" height="300" frameborder="1" src="http://maps.google.com/maps?q='.$location['latitude'].','.$location['longitude'].'&amp;t=h&amp;ie=UTF8&amp;z=10&amp;output=embed" marginwidth="0" marginheight="0"/>';
  46. }
  47. }else{
  48. $json['data'][] = 'Please install php5-geoip module and geoip database.';
  49. }
  50. }
  51. echo json_encode($json);
  52. }else{
  53. echo json_encode(array('status'=>false));
  54. }
  55. ?>