Class: LookupIP::V4

Inherits:
Object
  • Object
show all
Defined in:
lib/lookupip/v4.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, country, state, city, isp) ⇒ V4



8
9
10
11
12
13
14
# File 'lib/lookupip/v4.rb', line 8

def initialize(ip, country, state, city, isp)
  @ip = ip
  @country = country
  @state = state
  @city = city
  @isp = isp
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



7
8
9
# File 'lib/lookupip/v4.rb', line 7

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



7
8
9
# File 'lib/lookupip/v4.rb', line 7

def country
  @country
end

#ipObject (readonly)

Returns the value of attribute ip.



7
8
9
# File 'lib/lookupip/v4.rb', line 7

def ip
  @ip
end

#ispObject (readonly)

Returns the value of attribute isp.



7
8
9
# File 'lib/lookupip/v4.rb', line 7

def isp
  @isp
end

#stateObject (readonly)

Returns the value of attribute state.



7
8
9
# File 'lib/lookupip/v4.rb', line 7

def state
  @state
end

Class Method Details

.address(ip) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lookupip/v4.rb', line 16

def self.address(ip)
  @ip = ip
  uri = URI("https://www.iplocation.net/?query=#{@ip}&submit=IP+Lookup")
  page = Net::HTTP.get(uri)
  page = Nokogiri::HTML(page)
  @results = LookupIP::V4.new(
    @ip,
    page.xpath('//*[@id="wrapper"]/section/div/div/div[1]/div[8]/div/table/tbody[1]/tr/td[2]').text.strip,
    page.xpath('//*[@id="wrapper"]/section/div/div/div[1]/div[8]/div/table/tbody[1]/tr/td[3]').text.strip,
    page.xpath('//*[@id="wrapper"]/section/div/div/div[1]/div[8]/div/table/tbody[1]/tr/td[4]').text.strip,
    page.xpath('//*[@id="wrapper"]/section/div/div/div[1]/div[8]/div/table/tbody[2]/tr/td[1]').text.strip
  )
end