Class: Shadowserver::ASN

Inherits:
Object
  • Object
show all
Defined in:
lib/shadowserver/asn.rb

Constant Summary collapse

@@server =
'asn.shadowserver.org'
@@port =
43

Class Method Summary collapse

Class Method Details

.origin(ip) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shadowserver/asn.rb', line 7

def ASN::origin(ip)
	t = TCPSocket.new(@@server,@@port)
	t.write("origin #{ip}\n")
	asn, cidr, asname, cc, domain, isp = t.read.chomp.split(/\|/).map{|x| x.strip}
	asn = asn.to_i
	t.close
	{
		"asn" => asn,
		"cidr" => cidr,
		"asname" => asname,
		"cc" => cc,
		"domain" => domain,
		"isp" => isp
	}
end

.peer(ip) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shadowserver/asn.rb', line 23

def ASN::peer(ip)
	t = TCPSocket.new(@@server,@@port)
	t.write("peer #{ip}\n")
	peers, asn, prefix, asname, cc, domain, isp = t.read.chomp.split(/\|/).map{|x| x.strip}
	asn = asn.to_i
	peers = peers.split(/ /).map{|x| x.to_i}
	t.close
	{
		"peers" => peers,
		"asn" => asn,
		"prefix" => prefix,
		"asname" => asname,
		"cc" => cc,
		"domain" => domain,
		"isp" => isp
	}
end

.prefix(asn) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/shadowserver/asn.rb', line 41

def ASN::prefix(asn)
	t = TCPSocket.new(@@server,@@port)
	t.write("prefix #{asn}\n")
	prefixes = t.read.chomp.split(/\n/)
	t.close
	prefixes
end