Berkeley CSUA MOTD:Entry 49324
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/08 [General] UID:1000 Activity:popular
7/8     

2008/3/4-7 [Computer/Networking, Computer/SW/Languages/Perl] UID:49324 Activity:moderate
3/4     Does anybody have some code or know of a program that will take a
        network/mask and return the list of address in that CIDR block?
        e.g. "iplist 10.10.10.0/24" and return 10.10.10.0 ... 10.10.10.255
        [I have a way to do this, but it involves distributing a large
        amount of code, which is kind of a hassle. Looking for something
        lightweight and either standard or easdy to rpm/port/yum install.]
        \_ shouldn't be hard to do, its all bitwise binary math.
          \_ Because I was interested in how to do it in perl, I hacked up
             some quick code.  ~mehlhaff/netmask.pl   for your enjoyment. -ERic
        \_ there are couple out there. The one I settled on is sipcalc
           \_ Thanks for the pointer. I only knew about the "builtin"
              ipcalc. I see sipcalc return the "usable range" in the
              form 10.10.10.1 - 10.10.10.254. Is there a way to get
              it to return each of the 254 addresses, one per line, which
              can be piped to another program's stdin etc.
        \_ doing  it in perl?  Net::IP  http://search.cpan.org/dist/Net-IP/IP.pm
        \_ doing  it in perl?  Net::IP
           http://search.cpan.org/dist/Net-IP/IP.pm
        \_ look at nmap code
           \- i thought the nmap code was somewhat hard to understand
              [this was maybe 2yrs ago]. however, you can steal this
              exact function and parser from a modern version of fping
              which supports the "-g" flag. nevertheless, i'd be interested
              in a real standalone untility for this. starting with fping,
              this is do-able in like 30min [you can also do it in 2 lines
              if you want to do this in a stupid but perfectly workable way].
              it would take me a lot longer to extract this from nmap. --psb
              ./fping-psb -n -g 10.10.10.0 10.10.10.56 | wc -l
                    57
              ./fping-psb -n -g 10.10.10.0/30 | wc -l
                     4
        \_ I wrote a script last year that basically produces the same output
           as psb's solution.  My perl vs. mehlhaff's perl.  Round 1: Fight!
           ~dbushong/bin/expand-ip-range  --dbushong
           \_ dbushong is definitely sexier than mehlhaff. meh!
           \_ Hah, oops.  Mine only expands the last two octets.  (i.e. doesn't
              do anything useful for /n where n < 16)  Ah well.  --dbushong
              \_ clever code vs. simple code w/comments. Two very different
                 styles to accomplish the similar things.  It is left as a
                 exercise to the student to decide which they like better. -ERic
2025/07/08 [General] UID:1000 Activity:popular
7/8     

You may also be interested in these entries...
2008/8/5-10 [Computer/Networking] UID:50788 Activity:nil
8/5     It looks like my company has started blocking HTTPS tunneling.
        I used to do this by tunneling SSH through the HTTP/HTTPS proxy
        server, but this seems to have stopped working. Does anyone know
        how the implementation of tunneling detection works, and whether
        there are widely available implementations? We run a bunch of MS
        stuff, so I imagine we're running an MS proxy server or something.
	...
2001/8/5-6 [Computer/Networking] UID:22011 Activity:very high
8/5     I've just setup a new firewall at home and I'm looking for a
        tool to test it out. Any recommendations?
        I'm also running a caching DNS server on the firewall and I'd
        like to setup a rule that allows the server to make queries
        and recieve responses but that blocks inbound queries. I can't
        seem to figure out how to do this though as my ipf fu is weak.
	...
1999/1/20-23 [Computer/Networking] UID:15259 Activity:high
1/20    If you know a person's IP address at which they're connected to
        the Internet, is there some sort of way to find out what kind of
        computer system they're using?
        \_ newest release of nmap will do this reasonably well by
           examing differences in tcp/ip stack.  There is another
           prog called queso that does this as well.  See also
	...
Cache (4760 bytes)
search.cpan.org/dist/Net-IP/IP.pm
DESCRIPTION ^ This module provides functions to deal with IPv4/IPv6 addresses. The module can be used as a class, allowing the user to instantiate IP objects, which can be single IP addresses, prefixes, or ranges of addresses. There is also a procedural way of accessing most of the functions. Most subroutines can take either IPv4 or IPv6 addresses transparently. The new() function accepts IPv4 and IPv6 addresses: $ip = new Net::IP ('dead:beef::/32') || die ... Optionnaly, the function can be passed the version of the IP. Otherwise, it tries to guess what the version is (see _is_ipv4() and _is_ipv6. OBJECT METHODS ^ Most of these methods are front-ends for the real functions, which use a procedural interface. Most functions return undef on failure, and a true value on success. A detailed description of the procedural interface is provided below. This method has the same functionality as the new() method, except that it reuses an existing object to store the new IP. It returns an IP object on success, and undef on failure. The error number is set whenever one of the methods produces an error. Also, a global $ERRNO variable is set when an error is produced. aggregate Aggregate 2 IPs - Append one range/prefix of IPs to another. The last address of the first range must be the one immediately preceding the first address of the second range. PROCEDURAL INTERFACE ^ These functions do the real work in the module. Like the OO methods, most of these return undef on failure. In order to access error codes and strings, instead of using $ip->error() and $ip->errno(), use the global functions Error() and Errno(). The functions of the procedural interface are not exported by default. In order to import these functions, you need to modify the use statement for the module: use Net::IP qw(:PROC); Error Returns the error string corresponding to the last error generated in the module. This is also useful for the OO interface, as if the new() function fails, we cannot call $ip->error() and so we have to use Error(). ip_bintoip Transform a bit string into an IP address Params : binary IP, IP version Returns : IP address on success, undef otherwise $ip = ip_bintoip ($binip,6); This is necessary because Math::BigInt is not compliant. Params : BigInt, IP version Returns : binary IP $binip = ip_inttobin ($bigint); ip_is_ipv4 Check if an IP address is of type 4 Params : IP address Returns : 1 (yes) or 0 (no) ip_is_ipv4($ip) and print "$ip is IPv4"; ip_is_ipv6 Check if an IP address is of type 6 Params : IP address Returns : 1 (yes) or 0 (no) ip_is_ipv6($ip) and print "$ip is IPv6"; ip_expand_address Expand an IP address from compact notation. Params : IP address, IP version Returns : expanded IP address or undef on failure $ip = ip_expand_address ($ip,4); ip_last_address_bin Return the last binary address of a prefix. Params : First binary IP, prefix length, IP version Returns : Binary IP $lastbin = ip_last_address_bin ($ip,$len,6); ip_get_prefix_length Get the prefix length for a given range of 2 IPs. Params : First binary IP, Last binary IP Returns : Length of prefix or undef (problem) $len = ip_get_prefix_length ($ip1,$ip2); Params : Four binary IPs (begin of range 1,end1,begin2,end2), IP version $IP_PARTIAL_OVERLAP (ranges overlap) $IP_NO_OVERLAP (no overlap) $IP_A_IN_B_OVERLAP (range2 contains range1) $IP_B_IN_A_OVERLAP (range1 contains range2) $IP_IDENTICAL (ranges are identical) undef (problem) (ip_is_overlap($rb1,$re1,$rb2,$re2,4) eq $IP_A_IN_B_OVERLAP) and do {}; ip_get_embedded_ipv4 Get an IPv4 embedded in an IPv6 address Params : IPv6 Returns : IPv4 string or undef (not found) $ip4 = ip_get_embedded($ip6); ip_aggregate Aggregate 2 ranges of binary IPs Params : 1st range (1st IP, Last IP), last range (1st IP, last IP), IP version Returns : prefix or undef (invalid) $prefix = ip_aggregate ($bip1,$eip1,$bip2,$eip2) || die ... ip_iptype Return the type of an IP (Public, Private, Reserved) Params : IP to test, IP version Returns : type or undef (invalid) $type = ip_iptype ($ip); ip_check_prefix Check the validity of a prefix Params : binary IP, length of prefix, IP version Returns : 1 or undef (invalid) Checks if the variant part of a prefix only has 0s, and the length is correct. ip_reverse Get a reverse name from a prefix Params : IP, length of prefix, IP version Returns : Reverse name or undef (error) $reverse = ip_reverse ($ip); ip_normalize Normalize data to a range/prefix of IP addresses Params : Data String (Single IP, Range, Prefix) Returns : ip1, ip2 (if range/prefix) or undef (error) ($ip1,$ip2) = ip_normalize ($data); ip_auth Return IP authority information from the IP::Authority module Params : IP, version Returns : Auth info (RI for RIPE, AR for ARIN, etc) $auth = ip_auth ($ip,4);