Advertisement
XyberSec

The PHP code to find the coordinates from GSM cells

Nov 25th, 2012
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.85 KB | None | 0 0
  1.  
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.   <head>
  4.     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  5.     <title>Tracking cell by Boris Landoni Example</title>
  6.    
  7.  
  8.    
  9.     <?php
  10.  
  11.  
  12.  
  13. function geturl()
  14. {
  15.  
  16.     if ($_REQUEST["myl"] != "") {
  17.       $temp = split(":", $_REQUEST["myl"]);
  18.       $mcc = substr("00000000".($temp[0]),-8);
  19.       $mnc = substr("00000000".($temp[1]),-8);
  20.       $lac = substr("00000000".($temp[2]),-8);
  21.       $cid = substr("00000000".($temp[3]),-8);   
  22.     } else {
  23.       $hex = $_REQUEST["hex"];
  24.       //echo "hex $hex";
  25.       if ($hex=="1"){
  26.             //echo "da hex to dec";
  27.             $mcc=substr("00000000".hexdec($_REQUEST["mcc"]),-8);
  28.             $mnc=substr("00000000".hexdec($_REQUEST["mnc"]),-8);
  29.             $lac=substr("00000000".hexdec($_REQUEST["lac"]),-8);
  30.             $cid=substr("00000000".hexdec($_REQUEST["cid"]),-8);
  31.            
  32.             $nlac[0]=substr("00000000".hexdec($_REQUEST["lac0"]),-8);
  33.             $ncid[0]=substr("00000000".hexdec($_REQUEST["cid0"]),-8);          
  34.             $nlac[1]=substr("00000000".hexdec($_REQUEST["lac1"]),-8);
  35.             $ncid[1]=substr("00000000".hexdec($_REQUEST["cid1"]),-8);
  36.             $nlac[2]=substr("00000000".hexdec($_REQUEST["lac2"]),-8);
  37.             $ncid[2]=substr("00000000".hexdec($_REQUEST["cid2"]),-8);
  38.             $nlac[3]=substr("00000000".hexdec($_REQUEST["lac3"]),-8);
  39.             $ncid[3]=substr("00000000".hexdec($_REQUEST["cid3"]),-8);
  40.             $nlac[4]=substr("00000000".hexdec($_REQUEST["lac4"]),-8);
  41.             $ncid[4]=substr("00000000".hexdec($_REQUEST["cid4"]),-8);
  42.             $nlac[5]=substr("00000000".hexdec($_REQUEST["lac5"]),-8);
  43.             $ncid[5]=substr("00000000".hexdec($_REQUEST["cid5"]),-8);
  44.            
  45.       }else{
  46.             //echo "lascio dec";   
  47.             $mcc = substr("00000000".$_REQUEST["mcc"],-8);
  48.             $mnc = substr("00000000".$_REQUEST["mnc"],-8);
  49.             $lac = substr("00000000".$_REQUEST["lac"],-8);
  50.             $cid = substr("00000000".$_REQUEST["cid"],-8);
  51.            
  52.             $nlac[0]=substr("00000000".($_REQUEST["lac0"]),-8);
  53.             $ncid[0]=substr("00000000".($_REQUEST["cid0"]),-8);        
  54.             $nlac[1]=substr("00000000".($_REQUEST["lac1"]),-8);
  55.             $ncid[1]=substr("00000000".($_REQUEST["cid1"]),-8);
  56.             $nlac[2]=substr("00000000".($_REQUEST["lac2"]),-8);
  57.             $ncid[2]=substr("00000000".($_REQUEST["cid2"]),-8);
  58.             $nlac[3]=substr("00000000".($_REQUEST["lac3"]),-8);
  59.             $ncid[3]=substr("00000000".($_REQUEST["cid3"]),-8);
  60.             $nlac[4]=substr("00000000".($_REQUEST["lac4"]),-8);
  61.             $ncid[4]=substr("00000000".($_REQUEST["cid4"]),-8);
  62.             $nlac[5]=substr("00000000".($_REQUEST["lac5"]),-8);
  63.             $ncid[5]=substr("00000000".($_REQUEST["cid5"]),-8);
  64.       }
  65.     }
  66.     //echo "MCC : $mcc <br> MNC : $mnc <br>LAC : $lac <br>CID : $cid <br>";
  67.     return array ($mcc, $mnc, $lac, $cid, $nlac, $ncid);
  68. }
  69. function decodegoogle($mcc,$mnc,$lac,$cid)
  70. {
  71.  
  72.  
  73.     $mcch=substr("00000000".dechex($mcc),-8);
  74.     $mnch=substr("00000000".dechex($mnc),-8);
  75.     $lach=substr("00000000".dechex($lac),-8);
  76.     $cidh=substr("00000000".dechex($cid),-8);
  77.    
  78.     echo "<tr><td>Hex </td><td>MCC: $mcch </td><td>MNC: $mnch </td><td>LAC: $lach </td><td>CID: $cidh </td></tr></table>";
  79.  
  80. $data =
  81. "\x00\x0e". // Function Code?
  82. "\x00\x00\x00\x00\x00\x00\x00\x00". //Session ID?
  83. "\x00\x00". // Contry Code
  84. "\x00\x00". // Client descriptor
  85. "\x00\x00". // Version
  86. "\x1b". // Op Code?
  87. "\x00\x00\x00\x00". // MNC
  88. "\x00\x00\x00\x00". // MCC
  89. "\x00\x00\x00\x03".
  90. "\x00\x00".
  91. "\x00\x00\x00\x00". //CID
  92. "\x00\x00\x00\x00". //LAC
  93. "\x00\x00\x00\x00". //MNC
  94. "\x00\x00\x00\x00". //MCC
  95. "\xff\xff\xff\xff". // ??
  96. "\x00\x00\x00\x00"  // Rx Level?
  97. ;
  98.  
  99.  
  100.  
  101.  
  102. $init_pos = strlen($data);
  103. $data[$init_pos - 38]= pack("H*",substr($mnch,0,2));
  104. $data[$init_pos - 37]= pack("H*",substr($mnch,2,2));
  105. $data[$init_pos - 36]= pack("H*",substr($mnch,4,2));
  106. $data[$init_pos - 35]= pack("H*",substr($mnch,6,2));
  107. $data[$init_pos - 34]= pack("H*",substr($mcch,0,2));
  108. $data[$init_pos - 33]= pack("H*",substr($mcch,2,2));
  109. $data[$init_pos - 32]= pack("H*",substr($mcch,4,2));
  110. $data[$init_pos - 31]= pack("H*",substr($mcch,6,2));
  111. $data[$init_pos - 24]= pack("H*",substr($cidh,0,2));
  112. $data[$init_pos - 23]= pack("H*",substr($cidh,2,2));
  113. $data[$init_pos - 22]= pack("H*",substr($cidh,4,2));
  114. $data[$init_pos - 21]= pack("H*",substr($cidh,6,2));
  115. $data[$init_pos - 20]= pack("H*",substr($lach,0,2));
  116. $data[$init_pos - 19]= pack("H*",substr($lach,2,2));
  117. $data[$init_pos - 18]= pack("H*",substr($lach,4,2));
  118. $data[$init_pos - 17]= pack("H*",substr($lach,6,2));
  119. $data[$init_pos - 16]= pack("H*",substr($mnch,0,2));
  120. $data[$init_pos - 15]= pack("H*",substr($mnch,2,2));
  121. $data[$init_pos - 14]= pack("H*",substr($mnch,4,2));
  122. $data[$init_pos - 13]= pack("H*",substr($mnch,6,2));
  123. $data[$init_pos - 12]= pack("H*",substr($mcch,0,2));
  124. $data[$init_pos - 11]= pack("H*",substr($mcch,2,2));
  125. $data[$init_pos - 10]= pack("H*",substr($mcch,4,2));
  126. $data[$init_pos - 9]= pack("H*",substr($mcch,6,2));
  127.  
  128. if ((hexdec($cid) > 0xffff) && ($mcch != "00000000") && ($mnch != "00000000")) {
  129.   $data[$init_pos - 27] = chr(5);
  130. } else {
  131.   $data[$init_pos - 24]= chr(0);
  132.   $data[$init_pos - 23]= chr(0);
  133. }
  134.  
  135.  
  136.  
  137. $context = array (
  138.         'http' => array (
  139.             'method' => 'POST',
  140.             'header'=> "Content-type: application/binary\r\n"
  141.                 . "Content-Length: " . strlen($data) . "\r\n",
  142.             'content' => $data
  143.             )
  144.         );
  145.  
  146.  
  147.    
  148. $xcontext = stream_context_create($context);
  149. $str=file_get_contents("http://www.google.com/glm/mmap",FALSE,$xcontext);
  150.  
  151.  
  152.  
  153. if (strlen($str) > 10) {
  154.   $lat_tmp = unpack("l",$str[10].$str[9].$str[8].$str[7]);
  155.   $lat = $lat_tmp[1]/1000000;
  156.   $lon_tmp = unpack("l",$str[14].$str[13].$str[12].$str[11]);
  157.   $lon = $lon_tmp[1]/1000000;
  158.   $raggio_tmp = unpack("l",$str[18].$str[17].$str[16].$str[15]);
  159.   $raggio = $raggio_tmp[1]/1;
  160.   } else {
  161.   echo "Not found!";
  162.   $lat = 0;
  163.   $lon = 0;
  164.   }
  165.   return array($lat,$lon,$raggio);
  166.  
  167.  
  168. }
  169.  
  170.  
  171.  
  172.  
  173. list($mcc,$mnc,$lac,$cid, $nlac, $ncid)=geturl();
  174.  
  175.  
  176. echo "<table cellspacing=30><tr><td>Dec</td><td>MCC: $mcc </td><td>MNC: $mnc </td><td>LAC: $lac </td><td>CID: $cid </td></tr>";
  177.  
  178.  
  179.  
  180.  
  181.  
  182. list ($lat,$lon,$raggio)=decodegoogle($mcc,$mnc,$lac,$cid);
  183.  
  184.   echo "<br>Google result for the main Cell<br>";
  185.   echo "Lat=$lat <br> Lon=$lon <br> Range=$raggio m<br>";
  186.   echo "<a href=\"http://maps.google.it/maps?f=q&source=s_q&hl=it&geocode=&q=$lat,$lon&z=14\" TARGET=\"_blank\" >See on Google maps</a> <BR> <br>";
  187.  
  188.  
  189.   for ($contatore=0; $contatore < (count($nlac)); $contatore++) {
  190.     if ($nlac[$contatore]==0) {
  191.         //echo "trovato campo vuoto al contatore $contatore<BR>";
  192.         $ncelle=$contatore;
  193.         break;
  194.     }  
  195. }
  196.  
  197. for ($contatore=0; $contatore < ($ncelle); $contatore++) {
  198.     echo "LAC: $nlac[$contatore]\t CID: $ncid[$contatore]<BR>";
  199.     list ($nlat[$contatore],$nlon[$contatore],$nraggio[$contatore])=decodegoogle($mcc,$mnc,$nlac[$contatore],$ncid[$contatore]);
  200.     echo "<br>Google result for the Neighbor Cell $contatore <br>";
  201.     echo "nLat=$nlat[$contatore] <br> nLon=$nlon[$contatore] <br> nRaggio=$nraggio[$contatore] m<br><br>";
  202. }
  203.  
  204.  
  205.  
  206.   echo "<div id=\"map\" style=\"width: 100%; height: 700px\"></div>";
  207.   echo "<script type=\"text/javascript\">";
  208.   echo "var latgoogle=$lat;";
  209.   echo "var longoogle=$lon;";
  210.   echo "var raggio=$raggio;";
  211.  
  212.  
  213. //creo un file contenente le coordinate delle celle ****  
  214.     $stringa_xml_doc = " <markers>\n\t";
  215.     $stringa_xml_doc =$stringa_xml_doc. "<marker lat=\"$lat\" lng=\"$lon\" rag=\"$raggio\" html=\"Main cell\" ico=\"antred\" label=\"Main\" />";
  216.         for($contatore= 0; $contatore < $ncelle; $contatore++)
  217.         {
  218.             if ($nlat[$contatore]!=0) {
  219.                 $stringa_xml_doc =$stringa_xml_doc. "<marker lat=\"$nlat[$contatore]\" lng=\"$nlon[$contatore]\" rag=\"$nraggio[$contatore]\" html=\"Cell $contatore\" ico=\"antbrown\" label=\"Marker $contatore\" />";
  220.             }
  221.            
  222.         }
  223.     $stringa_xml_doc =$stringa_xml_doc."\n </markers>";
  224.      
  225.                          
  226.     echo ($stringa_xml_doc);
  227.     //$stringa_xml = $stringa_xml_dtd.$stringa_xml_doc;
  228.     $stringa_xml = $stringa_xml_doc;
  229.  
  230.     $file_name = "celle_xml.xml";
  231.     $file = fopen ($file_name,"w");
  232.     $num = fwrite ($file, $stringa_xml);
  233.  
  234.     fclose($file);
  235.  
  236.     echo("File XML creato con successo!!");
  237.  
  238. //***
  239.  
  240.  
  241.   echo "nLat=new Array();";
  242.   echo "nLon=new Array();";
  243.   echo "nraggio=new Array();";
  244.   for ($contatore=0; $contatore < ($ncelle); $contatore++)
  245.             {
  246.   echo "        nLat [$contatore]   =$nlat[$contatore];
  247.                 nLon [$contatore]   =$nlon[$contatore];
  248.                 nraggio [$contatore]=$nraggio[$contatore];";
  249.                
  250.                
  251.             }
  252.  
  253.   echo "</script>";
  254.  
  255. ?>
  256.  
  257.  
  258.         <center>
  259.         <br>
  260.         <br>
  261.         <center>
  262.             <br>
  263.             <br>
  264.             <iframe width='100%' height='540' marginwidth='0' marginheight='0' scrolling='no' frameborder='0'  src='http://open-electronics.org/fb/' ></iframe>
  265.         </center>
  266. <br>
  267. <br>
  268. </center>
  269.  
  270.     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAIJFMStkxCl4SCny-4ljyrBRkrgiUOwoahV4KonZmGOdSmhVVVBTizYtL9IQMT4sND3EJvMdlOrIA8g" type="text/javascript"></script>
  271.  
  272.   </head>
  273.  
  274.  
  275.  
  276.  
  277.  <body onunload="GUnload()">
  278.  
  279.         <center>
  280.         <br>
  281.         <br>
  282.         <script type="text/javascript"><!--
  283. google_ad_client = "ca-pub-5248152858136551";
  284. /* OE Link Banner post */
  285. google_ad_slot = "3312240372";
  286. google_ad_width = 468;
  287. google_ad_height = 60;
  288. //-->
  289. </script>
  290. <script type="text/javascript"
  291. src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
  292. </script>
  293. <br>
  294. <br>
  295. </center>
  296.    
  297.  
  298.  
  299.     <script type="text/javascript">
  300.    
  301.    
  302.    
  303.    //function initialize() {
  304.       if (GBrowserIsCompatible()) {
  305.         //alert("boris2");
  306.  
  307.        
  308.      
  309.     //}
  310.    
  311.     // This function picks up the click and opens the corresponding info window
  312.       function myclick(i) {
  313.         GEvent.trigger(gmarkers[i], "click");
  314.       }
  315.    
  316.    
  317.         var map = new GMap2(document.getElementById("map"));
  318.         //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
  319.         map.setUIToDefault();  
  320.    
  321.     function cursore() {
  322.         alert("boris");
  323.         var pointg = new GLatLng(latgoogle,longoogle);
  324.         alert(pointg);
  325.     }
  326.    
  327.  
  328.      
  329.      
  330.       // A function to create the marker and set up the event window
  331.       function createMarker(point,name,html,icona) {       
  332.         var marker = new GMarker(point,markerOptions);
  333.         GEvent.addListener(marker, "click", function() {
  334.           marker.openInfoWindowHtml(html);
  335.         });
  336.         return marker;
  337.       }
  338.      
  339.      
  340.      
  341. // Read the data from example.xml
  342.       GDownloadUrl("celle_xml.xml", function(doc) {
  343.         var xmlDoc = GXml.parse(doc);
  344.         var markers = xmlDoc.documentElement.getElementsByTagName("marker");
  345.          
  346.         for (var i = 0; i < markers.length; i++) {
  347.           // obtain the attribues of each marker
  348.           var lat = parseFloat(markers[i].getAttribute("lat"));
  349.           var lng = parseFloat(markers[i].getAttribute("lng"));
  350.           var raggio = parseFloat(markers[i].getAttribute("rag"));
  351.           var icona = markers[i].getAttribute("ico");
  352.           var Icon = new GIcon(G_DEFAULT_ICON);
  353.             Icon.image = icona + ".png";
  354.            
  355.             // Set up our GMarkerOptions object
  356.            
  357.                 markerOptions = { icon:Icon };
  358.            
  359.            
  360.           var point = new GLatLng(lat,lng);
  361.          
  362.           var html = markers[i].getAttribute("html");
  363.           var label = markers[i].getAttribute("label");
  364.          
  365.           // create the marker
  366.             if (icona=="antred") {
  367.                 var color="#FF0000";
  368.                 var fillColor="#FF6600";
  369.             }
  370.             else {
  371.                 var color="#FF6699";
  372.                 var fillColor="#FF99CC";
  373.             }
  374.           var thickness=4;
  375.           var opacity=0.4;
  376.          
  377.           var fillOpacity=0.2;
  378.  
  379.           var polyCircle=drawCircle(point, raggio, color, thickness, opacity, fillColor, fillOpacity);     
  380.           map.addOverlay(polyCircle);
  381.           var marker = createMarker(point,label,html,markerOptions);
  382.           map.addOverlay(marker);
  383.         }
  384.             map.setCenter(point, 13);
  385.         // put the assembled side_bar_html contents into the side_bar div
  386.         //document.getElementById("side_bar").innerHTML = side_bar_html;
  387.       });
  388.    
  389.  
  390.  
  391.         function drawCircle(center, radius, color, thickness, opacity, fillColor, fillOpacity)
  392.         {
  393.        
  394.             radiusMiles=radius*0.000621371192;
  395.             //alert(radiusMiles);
  396.             var degreesPerPoint = 8;
  397.             var radiusLat = radiusMiles * (1/69.046767); // there are >> >> > 69.046767 miles per degree latitude
  398.             var radiusLon = radiusMiles * (1/(69.046767 * Math.cos(parseFloat(center.lat()) * Math.PI / 180)));
  399.             var points = new Array();
  400.             //Loop through all degrees from 0 to 360
  401.             for(var i = 0; i < 360; i += degreesPerPoint)
  402.             {
  403.                 var point = new GLatLng(parseFloat(center.lat()) + (radiusLat * Math.sin(i * Math.PI / 180)), parseFloat(center.lng()) + (radiusLon * Math.cos(i * Math.PI / 180)));
  404.                     points.push(point);
  405.             }
  406.             points.push(points[0]);     // close the circle
  407.  
  408.             polyCircle = new GPolygon(points, color, thickness, opacity, fillColor, fillOpacity)
  409.             return polyCircle;
  410.         }
  411.  }
  412.  
  413.     </script>
  414.    
  415.    
  416. <script type="text/javascript">
  417.    
  418.   //cursore();  //carica il marcatore
  419.  
  420. </script>
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.   </body>
  428. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement