[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Fine tune a script to insert router

Posted on 2011-02-14
7
Medium Priority
?
908 Views
Last Modified: 2012-08-14
In Reference to thread, Say thanks to the person who helped me !
http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_26821466.html#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 $_;
}

Open in new window

0
Comment
Question by:richsark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 34894537
Strange!  Is this with a different dhcp.txt input file?  Please post the input so I can try running it here.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34894572
When I create a small file with just this input:

# 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"

Open in new window


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.
0
 
LVL 1

Author Comment

by:richsark
ID: 34894583
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:sjklein42
ID: 34894602
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 $_;
} 

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 34894619
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?
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 total points
ID: 34894651
To summarize the latest version of the code:

It grabs each #NET address, keeps the first 3 numbers and numerically adds "1" to the fourth number.  This is the gateway IP.

This new version of the code looks for the line containing "set optionvalue 3 STRING", whether it already has a non-zero IP or not, and substitutes the new gateway IP it computed from the #NET line.

The only difference is that the previous version of the code required the input IP to be all zeroes.  The new version doesn't care.  Nothing else changed.
0
 
LVL 1

Author Closing Comment

by:richsark
ID: 34894786
Thanks !!!

Good work
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Six Sigma Control Plans
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question