04-22-2015 07:52 AM
Hello guys,
can someone help me out with a TCL script for some 2960-CG Switches?
I need to change the IP Address of an interface vlan in the third octet for about …. uhm … many switches and they are not at my location so I don’t have console access :/
Could you write me a script which reads out the IP address of an interface vlan XXX
and sets the new address with a just in the third octet different address?
So this should look like following:
OLD:
int vlan 123
Ip address 10.20.30.40 255.255.252.0
NEW:
Int vlan 123
Ip address 10.20.50.40 255.255.252.0
Thank you very much!
Regards,
packettracer86
04-22-2015 01:52 PM
I'm not sure what the ask is here. You want the script to read in the ip address from a vlan, will it always be vlan123? If there are multiple vlan interfaces which vlan(s) need the IP address to be changed? Will the third octet always change from 30 to 50, or will it always be +20 from the existing 3rd octet?
Once the above is known is it your intention to manually log into every switch and paste a script into the tcl shell for the changes to take place? How do you intend to deploy the script?
04-23-2015 01:26 AM
Here are the answers to the questions:
1. The VLAN ist always interface vlan123.
2. There are no other INTERFACE vlans -> it is the management vlan for 2960 miniswitch
3. Yes the third octet will always change from 30 to 50
4. Now to the question how to deploy the script! First i thought about roll out the script in combination with a kron job (kron on the switch to start the script on a specific time..) over our management system BUT at the last night i had a nightmare.
My nightmare was the ip default-gateway it is allready set to the "new" ip range 10.20.48.1 255.255.252.0.
So the only chance to fix this messed up configs is to initiate/start another script on the next L3-Device which has an IP address in the same subnet OR to manually change the ip address on every (about 150) switches ://
Do you see any chance to run some kind of script on the L3 device which connects via telnet/ssh (based on a ip adress list i have) to the miniswitches and load in a script which changes the ip address??
(Mark to myself: Next time check configs generated via script twice.. )
04-23-2015 11:31 AM
I'm thinking of a policy that would do this:
The EEM script would have to be loaded onto the flash drive of all your routers.
Is the CDP dependency OK in your environment?
04-24-2015 12:19 AM
Hey Daniel,
that sounds exactly what i THOUGHT i would need. I just checked the "master" config of the miniswitches and ... well there is an access list on the vty line which will make the whole plan .... useless!
I am really sorry for wasting your time!! :/
It looks like the only way to change the ip address is to manually connect to every switch via the consoleport.
If you are still interestet in helping me, i have a last idea just to make it a "bit" easier to change the IP.
I connect to the con port and login by hand. Than i copy/paste in a script which will get started with the last line i paste (i hope you understand what i mean! i paste the script and the command to start that one).
And this script just reads out the ip address of interface vlan 123 and changes the ip in the third octect from x.x.30.x to x.x.50.x and makes a wr.
Thanks and regards!
04-24-2015 08:51 AM
This should do what you want. Paste this in when you are in exec mode:
tclsh
set mask "255.255.252.0"
set result [exec sh ip int brief | inc Vlan123]
regexp {([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)} $result match ip
regexp {([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)} $ip match first second third forth
regsub ($third) $third "50" third
set newip $first.$second.$third.$forth
ios_config "int vlan123" "ip address $newip $mask"
set result [exec sh ip int brief | inc Vlan123]
wr
Dan
04-28-2015 02:58 AM
Hello Daniel,
thank you for your response!
I will try out this tcl script in the next days and write back how it worked!
Regards
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide