[arin-tech-discuss] This is getting a little irritating ...
Andy Newton
andy at arin.net
Wed Jan 8 16:17:30 EST 2014
Eric,
I cannot replicate your problem. For the query you specify, JSON is being returned. See below:
$ curl http://whois.arin.net/rest/ip/204.12.8.28.json
{"net":{"@xmlns":{"ns3":"http:\/\/www.arin.net\/whoisrws\/netref\/v2","ns2":"http:\/\/www.arin.net\/whoisrws\/rdns\/v1","$":"http:\/\/www.arin.net\/whoisrws\/core\/v1"},"@termsOfUse":"https:\/\/www.arin.net\/whois_tou.html","registrationDate":{"$":"2011-02-03T11:23:31-05:00"},"ref":{"$":"http:\/\/whois.arin.net\/rest\/net\/NET-204-12-8-24-1"},"customerRef":{"@name":"Stylelife","@handle":"C02687103","$":"http:\/\/whois.arin.net\/rest\/customer\/C02687103"},"endAddress":{"$":"204.12.8.31"},"handle":{"$":"NET-204-12-8-24-1"},"name":{"$":"STYLELIFE"},"netBlocks":{"netBlock":{"cidrLength":{"$":"29"},"endAddress":{"$":"204.12.8.31"},"description":{"$":"Reassigned"},"type":{"$":"S"},"startAddress":{"$":"204.12.8.24"}}},"originASes":{"originAS":{"$":"AS20021"}},"parentNetRef":{"@name":"HOSTMYSITE","@handle":"NET-204-12-0-0-1","$":"http:\/\/whois.arin.net\/rest\/net\/NET-204-12-0-0-1"},"startAddress":{"$":"204.12.8.24"},"updateDate":{"$":"2011-02-03T11:23:31-05:00"},"version":{"$":"4"}}}
If you can provide the date and time this anomaly occurred, we can check our server logs to see if there were any issues on our side.
Andy Newton,
Chief Engineer, ARIN
From: Eric Dynamic <ecsd at transpacific.net<mailto:ecsd at transpacific.net>>
Date: Saturday, January 4, 2014 8:08 PM
To: "arin-tech-discuss at arin.net<mailto:arin-tech-discuss at arin.net>" <arin-tech-discuss at arin.net<mailto:arin-tech-discuss at arin.net>>
Subject: [arin-tech-discuss] This is getting a little irritating ...
Now after having written a script that worked marvelously for at least several says, all of a sudden now it is failing.
Why? Because once again, your service is returning what it feels like versus what I asked for.
Here is what I got from asking for JSON:
processing 204.12.8.28
<?xml version='1.0'?><?xml-stylesheet type='text/xsl' href='http://whois.arin.net/xsl/website.xsl' ?><net xmlns="http://www.arin.net/whoisrws/core/v1"<http://www.arin.net/whoisrws/core/v1> xmlns:ns2="http://www.arin.net/whoisrws/rdns/v1"<http://www.arin.net/whoisrws/rdns/v1> xmlns:ns3="http://ww
w.arin.net/whoisrws/netref/v2" termsOfUse="https://www.arin.net/whois_tou.html"<https://www.arin.net/whois_tou.html>><registrationDate>2011-02-03T11:23:31-05:00</registrationDate><ref>http://whois.arin.net/rest/net/NET-204-12-8-24-1</ref><customerRef name="
Stylelife" handle="C02687103">http://whois.arin.net/rest/customer/C02687103</customerRef><endAddress>204.12.8.31</endAddress><handle>NET-204-12-8-24-1</handle><name>STYLELIFE</name><netBlocks><netBlock><cidrLength>29</ci
drLength><endAddress>204.12.8.31</endAddress><description>Reassigned</description><type>S</type><startAddress>204.12.8.24</startAddress></netBlock></netBlocks><originASes><originAS>AS20021</originAS></originASes><parentN
etRef name="HOSTMYSITE" handle="NET-204-12-0-0-1">http://whois.arin.net/rest/net/NET-204-12-0-0-1</parentNetRef><startAddress>204.12.8.24</startAddress><updateDate>2011-02-03T11:23:31-05:00</updateDate><version>4</versio
n></net>
204.12.8.28
no ns4:pft
Now I am getting XML.
I don't have time to keep figuring out new parsers. I already write the code for the JSON. And it was working, as I said, for several days just fine.
Now for no reason I can see, suddenly, asking for JSON gives me XML. I don't feel like writing something that has to try to figure out what you actually sent versus what I requested.
This time I request that you FIX THIS.
=================
#!/usr/local/bin/php
<?php
// SQL #####################################################################################################################################################################################
function sqlerr() //$ER_DUP_Entry=1062;
{ if(($e = mysql_errno()) == 1062) $h = "Duplicate Key, ignored."; else $h = mysql_error(); $h = str_replace("'","",$h); $m = "DB:$e:$h"; echo "$m\n"; }
function gqquery($q) { if(mysql_query("$q")) return 0; sqlerr(); return 1; }
function mqquery($q) { if($qr = mysql_query("$q")) return $qr; sqlerr(); return 0; }
function sqquery($q) { $r = false; if($qr = mqquery($q)) { $r = mysql_fetch_object($qr); if(!$r) $r = false; mysql_free_result($qr); } return($r); }
function attach() { global $db; $db = mysql_connect("localhost","*****","*****"); if(!$db) return(0); return(mysql_select_db("sdfilter",$db)); }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// MAIN
$aTZ = "America/Los_Angeles"; date_default_timezone_set($aTZ); // timezone (absurd format)
global $errno, $fh, $db; $db=0; // globals
error_reporting(0x1F); // complain about anything
$db = attach(); if(!$db) {echo("open db failed."); return(1);} // sordid error handling
$buf = "";
$v = array();
if(!($C = curl_init())) exit(0);
curl_setopt($C,CURLOPT_RETURNTRANSFER,true);
if(!($fh=fopen("php://stdin","r"))) exit(0);
for($line = 1;;$line++) {
if(!($A = fgets($fh))) break;
echo "processing $A\n";
if(4 != sscanf($A,"%d.%d.%d.%d",&$n3,&$n2,&$n1,&$n0)) break;
$AA = sprintf("%02X%02X%02X%02X",$n3,$n2,$n1,$n0);
if($r = sqquery("select afrom,ato,contact from abuse where afrom <= '$AA' and '$AA' <= ato limit 1")) {
echo "$A already found in abuse $r->afrom <= $AA <= $r->ato *$r->contact), ignoring request.\n";
continue;
}
curl_setopt($C,CURLOPT_URL,"http://whois.arin.net/rest/ip/$A/pft.json"<http://whois.arin.net/rest/ip/$A/pft.json>);
$pft = curl_exec($C);
echo "$pft\n"; // gives the output shown above
for($rc = 1;;) {
if(!$pft) { echo "$A: no pft\n"; break; }
$Q = json_decode($pft,true); $Q = $Q["ns4:pft"]; if(!$Q) { echo "$A no ns4:pft\n"; break; }
if(!isset($Q["poc"])) { echo "$A: no poc\n"; break; }
if(!isset($Q["poc"][0])) { echo "$A: no poc[0]\n"; break; }
$F = $Q["net"]["startAddress"]["$"]; if( 4 != sscanf($F,"%d.%d.%d.%d",&$n3,&$n2,&$n1,&$n0) ) break;
$afrom = sprintf("%02X%02X%02X%02X",$n3,$n2,$n1,$n0);
$T = $Q["net"]["endAddress"]["$"]; if( 4 != sscanf($T,"%d.%d.%d.%d",&$n3,&$n2,&$n1,&$n0) ) break;
$ato = sprintf("%02X%02X%02X%02X",$n3,$n2,$n1,$n0);
if( $afrom > $ato ) break;
$n = count($Q["poc"]); $contact = "";
for( $j = 0; $j < $n; $j++ ) {
//echo "$A poc $j description " . $Q["poc"][$j]["@relatedDescription"] ."\n";
if($Q["poc"][$j]["@relatedDescription"] == "Abuse") {
$m = count($Q["poc"][$j]["emails"]["email"]); // we either get [$] or [0]...[n] in this modern world
if($m == 1) {
$contact = $Q["poc"][$j]["emails"]["email"]["$"];
//echo "single records, $contact.\n";
}
else { // save the first contact in any case and if it or a later one contains "abuse", use that.
$contact = strtolower($Q["poc"][$j]["emails"]["email"][0]);
//echo "$A multiple records, default $contact.\n";
if(strstr($contact,"abuse")) break;
else for($k=1, $x = strtolower($Q["poc"][$j]["emails"]["email"][$k]); $k<$m;$k++) if(strstr($x,"abuse")) { $contact = $x; break; }
echo "$A multiple records, using $contact.\n";
}
break;
}
}
if(!$contact || $contact == "abuse at ripe.net"<mailto:abuse at ripe.net> || $contact == "abuse at arin.net"<mailto:abuse at arin.net> || $contact == "abuse at apnic.net"<mailto:abuse at apnic.net>) break; // if abuse at ripe.net<mailto:abuse at ripe.net> e.g. then should ask RIPE.
echo "RESULT:: $afrom - $ato\t$contact\n";
$afrom = sprintf("%08X",$afrom); $ato = sprintf("%08X",$ato);
gqquery("insert into abuse (afrom,ato,contact) values ('$afrom','$ato','$contact')");
gqquery("update counts set count = count + 1 where class='database/reqfilled'");
$rc = 0;
break;
}
// we no longer insert (a,0) into abuse to remember what we want.
}
curl_close($C);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
?>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.arin.net/pipermail/arin-tech-discuss/attachments/20140108/972721ed/attachment.html>
More information about the arin-tech-discuss
mailing list