def asn(hostname)
ip = hostname
if ip.kind_of?(String) && ip !~ /^[0-9.]*$/
ip = IPSocket.getaddress(hostname)
ip = '0.0.0.0' if ip == '::1'
end
ipnum = iptonum(ip)
if (@databaseType != GEOIP_ASNUM_EDITION)
throw "Invalid GeoIP database type, can't look up ASN by IP"
end
pos = seek_record(ipnum);
record = ""
@mutex.synchronize {
@file.seek(pos + (2*@record_length-1) * @databaseSegments[0])
record = @file.read(MAX_ASN_RECORD_LENGTH)
}
record = record.sub(/\000.*/, '')
if record =~ /^(AS\d+)\s(.*)$/
return [$1, $2]
end
end