Over a million developers have joined DZone.

IP Catcher

·
--Howto use--
the command line:
   ruby /path/to/ipcatcher.rb /path/to/filename
the program will print all the ip addresses which is inside the file.
 the program doesn't print the same ip address twice. with no duplications.
Done by Amer Jazaerly.there is no copyright.
have fun ;)


#!/usr/bin/ruby

def get_ips(file)
  ips = []
  File.read(file).to_a.each do |place|
    sf = 0
    while sfn = place.index(/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/,sf)
      sf = sfn + 3
      ips << $&
    end
  end
  return ips
end

get_ips(ARGV[0]).uniq.each { |ip| puts ip }
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}