Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ip = "192.168.73.173"
- nm = "255.255.255.224"
- ip_bits = []
- nm_bits = []
- ip.split(".").each do |bits|
- ip_bits << ("%08b" % bits)
- end
- nm.split(".").each do |bits|
- nm_bits << ("%08b" % bits)
- end
- network = []
- m = 0
- while m < 4
- block = ""
- n = 0
- while n < 8
- block += (ip_bits[m].split("")[n].to_i & nm_bits[m].split("")[n].to_i).to_s
- n += 1
- end
- network << block.to_i(2)
- m += 1
- end
- puts network.join(".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement