Strawberry Perl - Net::Netmask; Module



  • hi,

    I am trying to learn PERL. I want to use this function/module in PERL. I am not quite sure how to install / enable it. 

     

    output of perl -v ::--

    ___________________

    This is perl 5, version 12, subversion 3 (v5.12.3) built for MSWin32-x86-multi-t
    hread

    Copyright 1987-2010, Larry Wall

    Perl may be copied only under the terms of either the Artistic License or the
    GNU General Public License, which may be found in the Perl 5 source kit.

    Complete documentation for Perl, including FAQ lists, should be found on
    this system using "man perl" or "perldoc perl".  If you have access to the
    Internet, point your browser at http://www.perl.org/, the Perl Home Page.

     

    My Script test1.pl::--

    ________________

     

    use strict;
    use warnings;
    use Net::Netmask;

    $block = Net::Netmask->new('192.168.1.128/25');
    print "Base address: ", $block->base(), "\n";
    print "Broadcast address: ", $block->broadcast(), "\n";
    print "Net mask: ", $block->mask(), "\n";
    print "Host mask: ", $block->hostmask(), "\n";
    print "Bits: ", $block->bits(), "\n";
    print "Size: ", $block->size(), "\n";
    print "2:nd element: ", $block->nth(2), "\n";
     

    When i run it, i am getting the following output ::--

    ________________________________________________

    Global symbol "$block" requires explicit package name at test1.pl line 16.
    Global symbol "$block" requires explicit package name at test1.pl line 17.
    Global symbol "$block" requires explicit package name at test1.pl line 18.
    Global symbol "$block" requires explicit package name at test1.pl line 19.
    Global symbol "$block" requires explicit package name at test1.pl line 20.
    Global symbol "$block" requires explicit package name at test1.pl line 21.
    Global symbol "$block" requires explicit package name at test1.pl line 22.
    Global symbol "$block" requires explicit package name at test1.pl line 23.
    Execution of test1.pl aborted due to compilation errors.

     

    Any idea, how to fix it ??

     

    Thanks.



  • There were few lines in between with #. I have removed them and use the code mentioned only and getting the following ::--

     Global symbol "$block" requires explicit package name at test1.pl line 5.
    Global symbol "$block" requires explicit package name at test1.pl line 6.
    Global symbol "$block" requires explicit package name at test1.pl line 7.
    Global symbol "$block" requires explicit package name at test1.pl line 8.
    Global symbol "$block" requires explicit package name at test1.pl line 9.
    Global symbol "$block" requires explicit package name at test1.pl line 10.
    Global symbol "$block" requires explicit package name at test1.pl line 11.
    Global symbol "$block" requires explicit package name at test1.pl line 12.
    Execution of test1.pl aborted due to compilation errors.



  •  found the issue and fixed it. will try few different things to make my life difficult :-)



  • @TechUser245 said:

    found the issue and fixed it.
     

    Is it a secret? :)



  • nah mate, it s no secret. Just thought to mention it so smart people like you dont waste time on this to help me out ;)

    btw,

    Now, i thought lets try to find out the IP address of a computer using this script and try to change it later on. I was able to figure out the script to find the IP address.

    Is there a way I can ping that IP and if packets received is more than or eq 1, I can increase the IP by 1, do the same process and once i get the correct IP , change it using a script ??

    I am using the following code now ::--

    <font size="-1">use strict; use warnings; use diagnostics; use Net::Netmask;

    my $result = ipconfig | find "IPv4 Address";
    ($result) = $result =~ m/(\d+.\d+.\d+.\d+)/;
    print "OLD IP: $result\n";
    </font>

    and getting following expected result ::--

    OLD IP: 10.0.0.11

     


  • Discourse touched me in a no-no place

    @TechUser245 said:

    Now, i thought lets try to find out the IP address of a computer...
    Which one?



    C:\Documents and Settings\PJH..PJHXP>ipconfig | find "IP Address"

    IP Address. . . . . . . . . . . . : 10.0.2.15

    IP Address. . . . . . . . . . . . : 192.168.78.79

    IP Address. . . . . . . . . . . . : 172.19.52.5

    @TechUser245 said:

    Is there a way I can ping
    that IP and if packets received is more than or eq 1, I can increase the
    IP by 1, do the same process and once i get the correct IP ,





    C:\Documents and Settings\PJH.PJHXP>ping 10.0.2.15 -n 1



    Pinging 10.0.2.15 with 32 bytes of data:



    Reply from 10.0.2.15: bytes=32 time<1ms TTL=128



    Ping statistics for 10.0.2.15:

    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

    Approximate round trip times in milli-seconds:

    Minimum = 0ms, Maximum = 0ms, Average = 0ms



    C:\Documents and Settings\PJH.PJHXP>echo %ERRORLEVEL%

    0



    C:\Documents and Settings\PJH.PJHXP>ping 10.0.2.16 -n 1



    Pinging 10.0.2.16 with 32 bytes of data:



    Request timed out.



    Ping statistics for 10.0.2.16:

    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),



    C:\Documents and Settings\PJH.PJHXP>echo %ERRORLEVEL%

    1



    C:\Documents and Settings\PJH.PJHXP>


    change it using a script ??
    use netsh.


  •  Thanks Pjh.

     I found netsh , just trying to figure out how to use it using perl :-) regarding changind the IP address of which one ? - i got 2 NIC's and Local Area Network is the one , i am intereste in.

     btw, s it possible to take the value of IP address from a file and assign it to the LAN network - Local Area Connection ? Leave the script running in the background and move to the next IP address after say 12 hours or so.

    e.g. file name will be ip2.txt which contains ip address 192.168.10.2 , file name ip3.txt which contains ip address 192.168.10.3 etc.. once it reads the file ipx.txt where x=2 to 254, it gets the IP address and assings it to the LAN network. it leaves it like that for say 12 hours and then move to the next one ipx+1.txt and does the same.

    once it reaches the ipx+y where x+y=254, it resets it to ip2.txt and does the same again.

     


Log in to reply