By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,542 Members | 1,434 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,542 IT Pros & Developers. It's quick & easy.

Automatic IP address Generation

100+
P: 123
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..
Jul 29 '08 #1
Share this Question
Share on Google+
5 Replies


KevinADC
Expert 2.5K+
P: 4,059
Do you know any perl? Have you attempted to write any code if you do?
Jul 30 '08 #2

100+
P: 123
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
Jul 30 '08 #3

100+
P: 123
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.
Jul 30 '08 #4

KevinADC
Expert 2.5K+
P: 4,059
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
Jul 30 '08 #5

100+
P: 123
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.
Jul 30 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.