📜 ⬆️ ⬇️

Definition of the city and region of Russia by IP

And so, March 13, 2009 16:07 the following news appeared on this resource " Long-awaited XML-service !!! ".

This event made me extremely happy, I’d have such a service on such a resource and at once the playful hands combed!

Literally 10 minutes later, the simplest ip request code was ready, during the discussions it turned out to be as follows (done in curl):
')
function getip($GetRIP)
{
$data = "<ipquery><fields><all/></fields><ip-list><ip>" .$GetRIP. "</ip></ip-list></ipquery>" ;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://194.85.91.253:8090/geo/geo.html" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_HEADER, false );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$xml = curl_exec($ch);
curl_close($ch);

//echo $xml;

$messge= "!<message>(.*?)</message>!si" ;

preg_match($messge, $xml, $main_ar[ "message" ]);

if ($main_ar[ "message" ][1]!= "Not found" )
{
$district= "!<district>(.*?)</district>!si" ;
$region= "!<region>(.*?)</region>!si" ;
$town= "!<city>(.*?)</city>!si" ;

preg_match($district, $xml, $main_ar[ "district" ]);
preg_match($region, $xml, $main_ar[ "region" ]);
preg_match($town, $xml, $main_ar[ "city" ]);

$ArMain=array( "FIND" =>1, "DISTRICT" =>$main_ar[ "district" ][1], "REGION" =>$main_ar[ "region" ][1], "TOWN" =>$main_ar[ "city" ][1]);
return $ArMain;
}
else return array( "FIND" =>0);
}


* This source code was highlighted with Source Code Highlighter .
function getip($GetRIP)
{
$data = "<ipquery><fields><all/></fields><ip-list><ip>" .$GetRIP. "</ip></ip-list></ipquery>" ;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://194.85.91.253:8090/geo/geo.html" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_HEADER, false );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$xml = curl_exec($ch);
curl_close($ch);

//echo $xml;

$messge= "!<message>(.*?)</message>!si" ;

preg_match($messge, $xml, $main_ar[ "message" ]);

if ($main_ar[ "message" ][1]!= "Not found" )
{
$district= "!<district>(.*?)</district>!si" ;
$region= "!<region>(.*?)</region>!si" ;
$town= "!<city>(.*?)</city>!si" ;

preg_match($district, $xml, $main_ar[ "district" ]);
preg_match($region, $xml, $main_ar[ "region" ]);
preg_match($town, $xml, $main_ar[ "city" ]);

$ArMain=array( "FIND" =>1, "DISTRICT" =>$main_ar[ "district" ][1], "REGION" =>$main_ar[ "region" ][1], "TOWN" =>$main_ar[ "city" ][1]);
return $ArMain;
}
else return array( "FIND" =>0);
}


* This source code was highlighted with Source Code Highlighter .
function getip($GetRIP)
{
$data = "<ipquery><fields><all/></fields><ip-list><ip>" .$GetRIP. "</ip></ip-list></ipquery>" ;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://194.85.91.253:8090/geo/geo.html" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_HEADER, false );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$xml = curl_exec($ch);
curl_close($ch);

//echo $xml;

$messge= "!<message>(.*?)</message>!si" ;

preg_match($messge, $xml, $main_ar[ "message" ]);

if ($main_ar[ "message" ][1]!= "Not found" )
{
$district= "!<district>(.*?)</district>!si" ;
$region= "!<region>(.*?)</region>!si" ;
$town= "!<city>(.*?)</city>!si" ;

preg_match($district, $xml, $main_ar[ "district" ]);
preg_match($region, $xml, $main_ar[ "region" ]);
preg_match($town, $xml, $main_ar[ "city" ]);

$ArMain=array( "FIND" =>1, "DISTRICT" =>$main_ar[ "district" ][1], "REGION" =>$main_ar[ "region" ][1], "TOWN" =>$main_ar[ "city" ][1]);
return $ArMain;
}
else return array( "FIND" =>0);
}


* This source code was highlighted with Source Code Highlighter .



The result of the query presented in the code:

image

According to the code a couple of words, it returns:

Source: https://habr.com/ru/post/54728/


All Articles