467,114 Members | 1,367 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,114 developers. It's quick & easy.

Automatic IP address Generation

100+
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
  • viewed: 1215
Share:
5 Replies
KevinADC
Expert 2GB
Do you know any perl? Have you attempted to write any code if you do?
Jul 30 '08 #2
100+
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+
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 2GB
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+
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.

Similar topics

reply views Thread by Rasmus Fogh | last post: by
15 posts views Thread by Kannan Goundan | last post: by
1 post views Thread by Lonnie Princehouse | last post: by
4 posts views Thread by Petterson Mikael | last post: by
1 post views Thread by woessner@gmail.com | last post: by
reply views Thread by JoshforRefugee | last post: by
25 posts views Thread by sidd | last post: by
34 posts views Thread by =?ISO-8859-1?Q?Marcel_M=FCller?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.