Jump to content

need help turning a simple Python code into PHP.


BRT2010

Recommended Posts

Hi guys,

I have already posted about a php script, that would turn CellID information into Lat/Long, but obviously the topic itself had scared off potential answerers. Let me try again.

 

I have found a Python2 script that takes net, cid, lac information, passes it to google maps and brings back the lat/long coordinates, that I need so much.

 

net, cid, lac = 25002, 9164, 4000
import urllib

a = '000E00000000000000000000000000001B0000000000000000000000030000'
b = hex(cid)[2:].zfill( + hex(lac)[2:].zfill(
c = hex(divmod(net,100)[1])[2:].zfill( + hex(divmod(net,100)[0])[2:].zfill(
string = (a + b + c + 'FFFFFFFF00000000').decode('hex')

data = urllib.urlopen('http://www.google.com/glm/mmap',string)
r = data.read().encode('hex')
print float(int(r[14:22],16))/1000000, float(int(r[22:30],16))/1000000

 

It's very simple, but unfortunately I don't understated that HEX stuff, what it is and how it form.

 

Maybe someone could please help me transform this code into PHP ? ::)

 

Thanks!

I can't help. Although.. here is my best shot. I know some of the code is variables, the ones in which I thought were, I put on the $. Hope I'm on the right track..

$net = 25002;
$cid = 9164;
$lac = 4000;

import urllib;

$a = '000E00000000000000000000000000001B000000000000000 0000000030000';
$b = hex($cid)[2:].zfill( + hex($lac)[2:].zfill(;
$c = hex(divmod($net,100)[1])[2:].zfill( + hex(divmod($net,100)[0])[2:].zfill(;
string = ($a + $b + $c + 'FFFFFFFF00000000').decode($hex);

try {
    $data = urllib.urlopen('http://www.google.com/glm/mmap', string);
    $r = $data.read().encode($hex);
    if(len($r) > 14) {
        echo  float(int($r[14:22],16))/1000000, float(int($r[22:30],16))/1000000;
    } else {
        echo 'no data in google';
    }
} catch {
    echo 'connect error';
}

thanks for the input.

 

<?php

$net = 25002;
$cid = 9164;
$lac = 4000;

$a = '000E00000000000000000000000000001B0000000000000000000000030000'
$b = hex($cid)[2:].zfill( + hex($lac)[2:].zfill(
$c = hex(divmod($net,100)[1])[2:].zfill( + hex(divmod($net,100)[0])[2:].zfill(
$string = ($a + $b + $c + 'FFFFFFFF00000000').decode('hex')

$data = 'http://www.google.com/glm/mmap'.$string
$r = $data.read().encode('hex')
print float(int($r[14:22],16))/1000000, float(int($r[22:30],16))/1000000

?>

 

currently got that far. seems there's a problem with "hex($cid)[2:].zfill(8) + hex($lac)[2:].zfill(8)"...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.