Wednesday, July 11, 2007

asnumber.js

asnumber
http://www.networx.ch

http://eu.asnumber.networx.ch/asnumber/asnum?ip=207.46.248.109 
http://ws.arin.net/cgi-bin/whois.pl?queryinput=
http://ws.arin.net/cgi-bin/whois.pl?queryinput=8070
http://www.ripe.net/fcgi-bin/whois?form_type=advanced&full_query_string=&searchtext="+ ASNCurrentASNumber.getAS() 
http://www.networx.ch
eu.asnumber.networx.ch   # ASNumber European Server
us.asnumber.networx.ch   # ASNumber USA Server
ap.asnumber.networx.ch   # ASNumber Asia-Pacific Server





var server = ASNGetCharPref("server", "eu.asnumber.networx.ch");

var ASNCheckIPv4 = /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/
/* This entry will expire after 8 hours */
this.valid_until = (new Date()).getTime() + (60 * 60 * 8 * 1000);


this.isResolveable = function() {
/* Ignore martian IP space. */

// if (0.0.0.0/8) RFC1700
if (this.ib[0] == 0)
return false;

// if (10.0.0.0/8) RFC1918
if (this.ib[0] == 10)
return false;

// if (127.0.0.0/8) RFC1700
if (this.ib[0] == 127)
return false;

// if (169.254.0.0/16) RFC3330
if (this.ib[0] == 169 && this.ib[1] == 254)
return false;

//if (172.16.0.0/12) RFC1918
if (this.ib[0] == 172 && this.ib[1] >= 16 && this.ib[1] <= 32)
return false;

// if (192.0.2.0/24) RFC3330
if (this.ib[0] == 192 && this.ib[1] == 0 && this.ib[2] == 2)
return false;

//if (192.88.99.0/24) RFC3068
if (this.ib[0] == 192 && this.ib[1] == 88 && this.ib[2] == 99)
return false;

// if (192.168.0.0/16) RFC1918
if (this.ib[0] == 192 && this.ib[1] == 168)
return false;

//if (198.18.0.0/15) RFC2544
if (this.ib[0] == 198 && this.ib[1] >= 18 && this.ib[1] <= 19)
return false;

//if (224.0.0.0/4) RFC3171
if (this.ib[0] >= 224 && this.ib[0] <= 239)
return false;

//if (240.0.0.0/4) RFC1700
if (this.ib[0] >= 240 && this.ib[0] <= 255)
return false;

return true;
}
}



/* This entry will expire in 8 hours */
this.valid_until = (new Date()).getTime() + (60 * 60 * 8 * 1000);


this.getRIR = function() {
var m = this.doc.textContent.match(/RIR[\s]*\:[\s]*([A-Z]+)/);
if (m == null)
return "";

var db = m[1];

if (db == 'RIPENCC')
db = 'RIPE';

return db;
}



ASNXMLHttpRequest = new XMLHttpRequest();
ASNXMLHttpRequest.open("GET", "http://" + ASNASServer + "/asnumber/asnum?ip=" + ip.getFullIP(), true);
ASNXMLHttpRequest.overrideMimeType("text/plain");
ASNXMLHttpRequest.myData = ip;
ASNXMLHttpRequest.onerror = function(event) {
var self = event.target;

ASNDisplay("AS n/a", "Unable to contact ASN server or no response", "text");
}
ASNXMLHttpRequest.onload = function(event) {
var self = event.target;

if (self.status == 200) {
var doc = "" + self.responseText + "";
var xulobject = (new DOMParser()).parseFromString(doc, "application/xml");

var ip = self.myData.getIP();
var as = new ASNASCacheObject(xulobject);

if (as.isValid()) {
ASNASCache[ip] = as;
ASNDisplayASNumber(ASNASCache[ip]);
} else
ASNDisplayIP(self.myData);
} else
ASNDisplayIP(ip);
}

ASNXMLHttpRequest.send(null);

return;



function ASNLoadWhois(s) {
if (ASNCurrentASNumber == null)
return;

if (s == 'click' && ASNFastAccess == false)
return;

var db = ASNCurrentASNumber.getRIR();

if (db == '')
return;

var url = '';

if (db == 'ARIN')
url = "http://ws.arin.net/cgi-bin/whois.pl?queryinput=" + ASNCurrentASNumber.getAS();
else
url = "http://www.ripe.net/fcgi-bin/whois?form_type=advanced&full_query_string=&searchtext=" + ASNCurrentASNumber.getAS() + "&inverse_attributes=None&ip_search_lvl=Default%28nearest+match%29&alt_database=" + db + "&object_type=aut-num&filter_mail=ON";

if (ASNOpenTabs == true) {
var oldtab = getBrowser().selectedTab;

try {
ASNTab.linkedBrowser.loadURI(url, null, null);
} catch(e) {
ASNTab = getBrowser().addTab(url, null, null, null);
}

if (ASNOpenForeground == true)
getBrowser().selectedTab = ASNTab;
else
getBrowser().selectedTab = oldtab;
} else
window.open(url);
}