Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old July 30th, 2008, 12:53 AM
Member
 
Join Date: Apr 2008
Location: United states / India
Posts: 106
Default 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..
Reply
  #2  
Old July 30th, 2008, 03:55 AM
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Posts: 3,662
Default

Do you know any perl? Have you attempted to write any code if you do?
Reply
  #3  
Old July 30th, 2008, 06:43 PM
Member
 
Join Date: Apr 2008
Location: United states / India
Posts: 106
Default

Quote:
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
Expand|Select|Wrap|Line Numbers
  1.  use Socket qw( inet_aton inet_ntoa ); 
(using that )
But i really dont have idea about that..
thanks
Reply
  #4  
Old July 30th, 2008, 08:41 PM
Member
 
Join Date: Apr 2008
Location: United states / India
Posts: 106
Default

Quote:
Originally Posted by ajd335
Hi KevinADC ,

thanks
Hey Kevin ,
I have tried out the below.
Expand|Select|Wrap|Line Numbers
  1.  #!/usr/bin/perl
  2. open(HANDLE , "result3.txt") || die("Could not open file!");
  3. while(<HANDLE>)
  4. {
  5. chomp;
  6. use Socket qw( inet_aton inet_ntoa );
  7.  
  8. sub fr_dotted { unpack  'N', inet_aton @_ ? $_[0] : $_ }
  9. sub to_dotted { inet_aton  pack  'N', @_ ? $_[0] : $_ }
  10.  
  11. my $next = fr_dotted('100.1.3.41');
  12. my $max  = fr_dotted('100.1.3.50');
  13.  
  14. die if $next > $max;
  15. my $new = $next++;
  16. $new1 = to_dotted($new);
  17. print $new1;
  18. }
  19. close(HANDLE);
  20.  
But that does not give me the desired results.
Reply
  #5  
Old July 30th, 2008, 09:28 PM
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Posts: 3,662
Default

Quote:
Originally Posted by ajd335
Hey Kevin ,
I have tried out the below.
Expand|Select|Wrap|Line Numbers
  1.  #!/usr/bin/perl
  2. open(HANDLE , "result3.txt") || die("Could not open file!");
  3. while(<HANDLE>)
  4. {
  5. chomp;
  6. use Socket qw( inet_aton inet_ntoa );
  7.  
  8. sub fr_dotted { unpack  'N', inet_aton @_ ? $_[0] : $_ }
  9. sub to_dotted { inet_aton  pack  'N', @_ ? $_[0] : $_ }
  10.  
  11. my $next = fr_dotted('100.1.3.41');
  12. my $max  = fr_dotted('100.1.3.50');
  13.  
  14. die if $next > $max;
  15. my $new = $next++;
  16. $new1 = to_dotted($new);
  17. print $new1;
  18. }
  19. close(HANDLE);
  20.  
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.com
Reply
  #6  
Old July 30th, 2008, 09:59 PM
Member
 
Join Date: Apr 2008
Location: United states / India
Posts: 106
Default

Quote:
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.com
Hi KevinADC ,
Thanks for the help.
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles