code_junkie

What's the simplest way of adding one to a binary string in Perl?

Nov 11th, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. Argument "nr&" isn't numeric in addition (+) at test.pm line 95.
  2.  
  3. pack("N", unpack("N", $ip&$netmask) + 1)
  4.  
  5. use Socket;
  6.  
  7. $ip = pack("C4", 192,168,250,66); # why not inet_aton("192.168.250.66")
  8. $netmask = pack("C4", 255,255,255,0);
  9.  
  10. $ipi = unpack("N", $ip);
  11. $netmaski = unpack("N", $netmask);
  12.  
  13. $ip1 = pack("N", ($ipi&$netmaski)+1);
  14. print inet_ntoa($ip1), "n";
  15.  
  16. 192.168.250.1
Add Comment
Please, Sign In to add comment