richsark
asked on
Fine tune a script to insert router
In Reference to thread, Say thanks to the person who helped me !
https://www.experts-exchange.com/questions/26821466/req-script-to-insert-router-in-this-file.html?anchorAnswerId=34894213#a34894213
I noticed that :
# NET 172.21.240.0/23
Dhcp Server 1.1.1.1 add scope 172.21.240.0 255.255.254.0 "172.21.240.0-Vlan-551" ""
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 6 STRING "128.163.97.5" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 3 STRING "172.21.244.1"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 51 STRING "604800"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 44 STRING "128.163.111.170" "128.163.111.171"
Put an invalid router option optionvalue 3 STRING "172.21.244.1"
My calculations shows the gateway/router should be 172.21.240.1
I would appreciate someones help please
https://www.experts-exchange.com/questions/26821466/req-script-to-insert-router-in-this-file.html?anchorAnswerId=34894213#a34894213
I noticed that :
# NET 172.21.240.0/23
Dhcp Server 1.1.1.1 add scope 172.21.240.0 255.255.254.0 "172.21.240.0-Vlan-551" ""
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 6 STRING "128.163.97.5" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 3 STRING "172.21.244.1"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 51 STRING "604800"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 44 STRING "128.163.111.170" "128.163.111.171"
Put an invalid router option optionvalue 3 STRING "172.21.244.1"
My calculations shows the gateway/router should be 172.21.240.1
I would appreciate someones help please
while ( <> )
{
if ( /\# NET ([0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+)/ ) { $net = $1; $lastNum = $2+1; }
else
{
s/set optionvalue 3 STRING \"0.0.0.0\"/set optionvalue 3 STRING \"$net\.$lastNum\"/;
}
print $_;
}
Strange! Is this with a different dhcp.txt input file? Please post the input so I can try running it here.
When I create a small file with just this input:
it generates the correct 172.21.240.1 output.
Are you sure the optionvalue 3 line in the input file has 0.0.0.0, like this:
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 3 STRING "0.0.0.0"
If it doesn't have 0.0.0.0, it won't match.
# NET 172.21.240.0/23
Dhcp Server 1.1.1.1 add scope 172.21.240.0 255.255.254.0 "172.21.240.0-Vlan-551" ""
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 6 STRING "128.163.97.5" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 3 STRING "0.0.0.0"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 51 STRING "604800"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 44 STRING "128.163.111.170" "128.163.111.171"
it generates the correct 172.21.240.1 output.
Are you sure the optionvalue 3 line in the input file has 0.0.0.0, like this:
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 3 STRING "0.0.0.0"
If it doesn't have 0.0.0.0, it won't match.
ASKER
Ahh, so.... the orginal file did not have 0.0.0.0, it had
# NET ---
# NET 172.21.240.0/23
Dhcp Server 1.1.1.1 add scope 172.21.240.0 255.255.254.0 "172.21.240.0-Vlan-551" ""
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 6 STRING "128.163.97.5" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 3 STRING "172.21.244.1"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 51 STRING "604800"
So I guess, would it be hard to counter these types to insure in fact the router is set right??
Thanks
# NET ---
# NET 172.21.240.0/23
Dhcp Server 1.1.1.1 add scope 172.21.240.0 255.255.254.0 "172.21.240.0-Vlan-551" ""
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 6 STRING "128.163.97.5" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 3 STRING "172.21.244.1"
Dhcp Server 1.1.1.1 Scope 172.21.240.0 set optionvalue 51 STRING "604800"
So I guess, would it be hard to counter these types to insure in fact the router is set right??
Thanks
To replace all the optionvalue 3 strings regardless of their IPs in the input file, use this:
while ( <> )
{
if ( /\# NET ([0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+)/ ) { $net = $1; $lastNum = $2+1; }
else
{
s/set optionvalue 3 STRING \"[0-9\.]+\"/set optionvalue 3 STRING \"$net\.$lastNum\"/;
}
print $_;
}
ASKER
Cool, So the above has the correct logic right? I am just worried it may set what it wants, but I believe it does check the network regardless right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks !!!
Good work
Good work