Automatic IP address Generation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajd335
    New Member
    • Apr 2008
    • 123

    Automatic IP address Generation

    Hey all..
    I am trying to reset IP address of all PCs in the work- group.
    I have selected some criteria for that..
    e.g management Group : 100.1.3.41 to 100.1.3.50 or so
    support staff 100.1.4.41 to .....
    I have a text document in which I have all the records( IP n hostname ,different text files for management and support staff n so on)
    I want to have some perl script that will assign automatic IP address.
    e.g host1_001 100.22.22.11 (management)
    will change to 100.1.3.41
    and the next management workstation will get the next available IP address.
    So Is there any way we can achieve so in Perl...
    I will really appreciate your help..
    Thanks..
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Do you know any perl? Have you attempted to write any code if you do?

    Comment

    • ajd335
      New Member
      • Apr 2008
      • 123

      #3
      Originally posted by KevinADC
      Do you know any perl? Have you attempted to write any code if you do?
      Hi KevinADC ,
      I really dont know from where should i start.
      As i told earlier also ,
      I have one result.txt which contains hostname and IP for (e.g management group)
      the file looks like
      host1-001 10.22.33.22
      host2-001 10.33.68.254

      I want to have perl script which can change that to
      host1-001 10.1.3.41
      host2-001 10.1.3.42

      and the host3 will get the next available IP e.g 10.1.3.43
      I have gone through some modules in perl
      Code:
       use Socket qw( inet_aton inet_ntoa );
      (using that )
      But i really dont have idea about that..
      thanks

      Comment

      • ajd335
        New Member
        • Apr 2008
        • 123

        #4
        Originally posted by ajd335
        Hi KevinADC ,

        thanks
        Hey Kevin ,
        I have tried out the below.
        Code:
         #!/usr/bin/perl
        open(HANDLE , "result3.txt") || die("Could not open file!");
        while(<HANDLE>)
        {
        chomp;
        use Socket qw( inet_aton inet_ntoa );
        
        sub fr_dotted { unpack  'N', inet_aton @_ ? $_[0] : $_ }
        sub to_dotted { inet_aton  pack  'N', @_ ? $_[0] : $_ }
        
        my $next = fr_dotted('100.1.3.41');
        my $max  = fr_dotted('100.1.3.50');
        
        die if $next > $max;
        my $new = $next++;
        $new1 = to_dotted($new);
        print $new1;
        }
        close(HANDLE);
        But that does not give me the desired results.

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by ajd335
          Hey Kevin ,
          I have tried out the below.
          Code:
           #!/usr/bin/perl
          open(HANDLE , "result3.txt") || die("Could not open file!");
          while(<HANDLE>)
          {
          chomp;
          use Socket qw( inet_aton inet_ntoa );
          
          sub fr_dotted { unpack  'N', inet_aton @_ ? $_[0] : $_ }
          sub to_dotted { inet_aton  pack  'N', @_ ? $_[0] : $_ }
          
          my $next = fr_dotted('100.1.3.41');
          my $max  = fr_dotted('100.1.3.50');
          
          die if $next > $max;
          my $new = $next++;
          $new1 = to_dotted($new);
          print $new1;
          }
          close(HANDLE);
          But that does not give me the desired results.
          I have little experience with the Sockets module so I am not going to be able to help. If you do not get a suggestion here try asking on www.perlmonks.c om

          Comment

          • ajd335
            New Member
            • Apr 2008
            • 123

            #6
            Originally posted by KevinADC
            I have little experience with the Sockets module so I am not going to be able to help. If you do not get a suggestion here try asking on www.perlmonks.c om
            Hi KevinADC ,
            Thanks for the help.

            Comment

            Working...