<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: address code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 07 Sep 2008 05:50:40 GMT</pubDate>
    <description>DZone Snippets: address code</description>
    <item>
      <title>IP Catcher</title>
      <link>http://snippets.dzone.com/posts/show/5430</link>
      <description>--Howto use--&lt;br /&gt;the command line:&lt;br /&gt;   ruby /path/to/ipcatcher.rb /path/to/filename&lt;br /&gt;the program will print all the ip addresses which is inside the file.&lt;br /&gt; the program doesn't print the same ip address twice. with no duplications.&lt;br /&gt;Done by &lt;a href="http://www.amerj.info"&gt;Amer Jazaerly&lt;/a&gt;.there is no copyright.&lt;br /&gt;have fun ;)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;def get_ips(file)&lt;br /&gt;  ips = []&lt;br /&gt;  File.read(file).to_a.each do |place|&lt;br /&gt;    sf = 0&lt;br /&gt;    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)&lt;br /&gt;      sf = sfn + 3&lt;br /&gt;      ips &lt;&lt; $&amp;&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  return ips&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;get_ips(ARGV[0]).uniq.each { |ip| puts ip }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 26 Apr 2008 08:18:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5430</guid>
      <author>amer (Amer Jazaerly)</author>
    </item>
    <item>
      <title>Convert an integer to IP string</title>
      <link>http://snippets.dzone.com/posts/show/5323</link>
      <description>Convert an integer to IP. I don't think you can do this with IPAddr, but I could be wrong&lt;br /&gt;&lt;br /&gt;Edit, the original didn't work for low ranges.&lt;br /&gt;&lt;br /&gt;And I was wrong about the IPAddr thing. I should have google'd better.&lt;br /&gt;&lt;br /&gt;IPAddr.new(16909060, Socket::AF_INET).to_s&lt;br /&gt;</description>
      <pubDate>Fri, 04 Apr 2008 21:30:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5323</guid>
      <author>markpercival (Mark Percival)</author>
    </item>
    <item>
      <title>Ping a range of IP addresses</title>
      <link>http://snippets.dzone.com/posts/show/5210</link>
      <description>&lt;code&gt;&lt;br /&gt;(1..254).each {|i| puts ": found 192.168.1.#{i}" if  `ping 192.168.1.#{i} -c 1 -w 1`.match(/ttl/) }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 11 Mar 2008 09:06:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5210</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Format IPv4 address in octal binary format and vice versa (Ruby / Rails)</title>
      <link>http://snippets.dzone.com/posts/show/4931</link>
      <description>Format an IPv4 address like 192.168.1.1 in dotted binary format like 11000000.10101000.00000001.00000001&lt;br /&gt;You also need this class: http://snippets.dzone.com/posts/show/2472&lt;br /&gt;For Rails: Put this in your controller!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  # convert a dotted decimal IPv4 address to dotted binary format&lt;br /&gt;  def ipv4_to_binary(ipv4addr)&lt;br /&gt;    ia = ipv4addr.to_s.split('.')&lt;br /&gt;    if ia.size != 4&lt;br /&gt;      return "0.0.0.0"&lt;br /&gt;    end&lt;br /&gt;    output = ""&lt;br /&gt;    i = 1&lt;br /&gt;    for octett in ia&lt;br /&gt;      output = output + octett.to_i.to_s(2).using("########","0",true)&lt;br /&gt;      if i &lt; 4&lt;br /&gt;        output = output + "."&lt;br /&gt;      end&lt;br /&gt;      i += 1&lt;br /&gt;    end&lt;br /&gt;    return output&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  # convert a IPv4 adress in binary dotted format to a dotted IPv4 address&lt;br /&gt;  def binary_to_ipv4(ipv4addr)&lt;br /&gt;    ia = ipv4addr.to_s.split('.')&lt;br /&gt;    if ia.size != 4&lt;br /&gt;      return "0.0.0.0"&lt;br /&gt;    end&lt;br /&gt;    output = ""&lt;br /&gt;    i = 1&lt;br /&gt;    for octett in ia&lt;br /&gt;      output = output + octett.to_s.to_i(2).to_s&lt;br /&gt;      if i &lt; 4&lt;br /&gt;        output = output + "."&lt;br /&gt;      end&lt;br /&gt;      i += 1&lt;br /&gt;    end&lt;br /&gt;    return output&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 28 Dec 2007 14:12:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4931</guid>
      <author>MichaelWhi (Michael Whittaker)</author>
    </item>
    <item>
      <title>Python - My External IP Address</title>
      <link>http://snippets.dzone.com/posts/show/3034</link>
      <description>// My external ip address&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import urllib&lt;br /&gt;&lt;br /&gt;url = urllib.URLopener()&lt;br /&gt;resp = url.open('http://myip.dk')&lt;br /&gt;html = resp.read(114)&lt;br /&gt;&lt;br /&gt;end = html.find("&lt;/title&gt;")&lt;br /&gt;start = html.find("IP:") + 3&lt;br /&gt;&lt;br /&gt;print html[start:end].strip()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 25 Nov 2006 06:02:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3034</guid>
      <author>whitetiger ()</author>
    </item>
  </channel>
</rss>
