Re: Is it possible to take the IP address from a file and assign it to LAN interface for certain period of time
by zwon (Abbot) on Sep 11, 2011 at 09:14 UTC
|
| [reply] |
|
|
Thanks zwon. i will check ifconfig and system.
Thanks Perlbotics. I am faily new to perl but will try to decode the config given by you.
Here is some more information ::--
* What platform (Windows, Unix, ..., any)? - this is on windows server.
* Switch IP at fixed times or after roughly 12 hours (free floating)? - roughly at 12 hours. i was thinking depending upon the success of this, I may change it to more or less hours. It should be fixed and knows in advance though.
* One or more instances (on several hosts) running? - Just one instance on this server.
* Daemon or cronjob-triggered program? - it is running on VM ware.
* Is this an XY Problem? E.g., can it be solved by DHCP? - it cant be solved by DHCP as my server is connected to the router and if i config DHCP on the router, any device connecting to the router , may opt for that IP hence i need to have it on the client side which is the server
* Security, logging, monitoring, configuration, etc. - i am looking forward to rotate the IP on the server as a part of my testing. i was wondering, when it goes to file ipx.txt, it uses the F5 function of the notepad to advise the IP was changed at certain day and time for me to keep a log of it. apart from it, no other security or monitoring is required.
| [reply] |
Re: Is it possible to take the IP address from a file and assign it to LAN interface for certain period of time
by Perlbotics (Archbishop) on Sep 11, 2011 at 09:33 UTC
|
Short answer: yes!
Do you really need 253 configuration files with predictable name/contents mapping? If these files
are required by an external tool to set the IP, then it would be smarter to generate a temporary config
file on demand by the Perl program.
Furthermore, some questions to ask (yourself) to improve your specification:
- What platform (Windows, Unix, ..., any)?
- Switch IP at fixed times or after roughly 12 hours (free floating)?
- One or more instances (on several hosts) running?
- Daemon or cronjob-triggered program?
- Is this an XY Problem? E.g., can it be solved by DHCP?
- Security, logging, monitoring, configuration, etc.
Because, it's Sunday, here's a template to fiddle with... ;-)
use strict;
use warnings;
use constant {
START_IP_BYTE4 => 2,
MAX_IP_BYTE4 => 254,
SLEEP => 12 * 3600
};
my @ip = qw(192 168 10 2);
$ip[3] = shift || START_IP_BYTE4;
while ( 'true' ) {
set_ip( @ip );
$ip[3]++;
$ip[3] = START_IP_BYTE4 if $ip[3] > MAX_IP_BYTE4;
print "Next change: " . localtime( time() + SLEEP ) . "\n";
sleep SLEEP; # floating!
}
die "oops! $! / $@";
sub set_ip {
my @ip = @_;
my $ip = join( '.', @ip );
print "Setting local IP to $ip...\n";
print "Load file 'ip$ip[3].txt' ???\n";
#TODO: set local IP
}
CPAN-search-terms-of-interest: cron, daemon, ifconfig, ...
| [reply] [d/l] |
Re: Is it possible to take the IP address from a file and assign it to LAN interface for certain period of time
by JavaFan (Canon) on Sep 11, 2011 at 10:14 UTC
|
Uhm, networks do not have IP addresses. And, for that matter, neither have computers. *Interfaces* have IP addresses, and a computer can have multiple interfaces (say, its ethernet interface, its wireless interface and its loopback interface), and each interface may have multiple IP addresses.
If your question is, "can I assign an IP address to one of my computers interfaces", the answer is, obviously, yes. After all, when you turn on your computer, none of its interfaces has an IP address. And they do get one after a while. | [reply] |
|
|
Thanks for the input Javafan. I should have explained it a bit better. My server got 2 NIC's and I am trying to change the IP of NIC - 1 --> Local Area Connection.
Btw, it is not right to say that when you turn on your computer, none of its Interfaces has an IP address. if you have assigned a static IP, it will be there irrespective of the status of the network :-)
| [reply] |
|
|
Even with a "static" IP, the IP address isn't assigned to the interface when turning on the computer. It's during the boot process that the address is assigned - be it by DHCP, or read from a configuration file. Static here just means that the local policy says your interface will be assigned the same IP address.
| [reply] |
Re: Is it possible to take the IP address from a file and assign it to LAN interface for certain period of time
by CountZero (Bishop) on Sep 11, 2011 at 19:16 UTC
|
I am not a network specialist at all, hence my question: what use is it to change the IP of your router or other device every x hours?
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] |
|
|
| [reply] |
|
|
I doubt it, the IP seems on a LAN, so unless he wants to spam his co-workers ...
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] |
Re: Is it possible to take the IP address from a file and assign it to LAN interface for certain period of time
by Anonymous Monk on Sep 11, 2011 at 13:02 UTC
|
It will require "rootly privileges" on any system, and it might well disrupt other networked services that might be using the interface at the same time. Proceed with profound caution, if at all. | [reply] |