Have you ever had to clear some specific NAT translations while avoiding to drop them all? You have to enter a long and annoying command such this a lot of times:
clear ip nat translation udp inside 1.2.3.4 7021 192.168.0.112 7021 outside 5.6.7.8 5060 5.6.7.8 5060
And you know, you have to do it many times, for every NAT entry you have to clear… and those entries are all there, within a single command output:
#show ip nat translations | inc 192.168.0.112
udp 1.2.3.4:7021 192.168.0.112:7021 5.6.7.8:5060 5.6.7.8:5060
udp 1.2.3.4:7022 192.168.0.112:7022 5.6.7.8:5060 5.6.7.8:5060
Well, I was bored once too often, so I’ve built a little tool: you have just to copy show ip nat translations entries you have to clear, paste them into this tool, and it builds the clear ip nat translation statements for you! ready to be pasted into your telnet/ssh client.
It’s an HTML page with a simple javascript; you can find it online, or here is the source code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Cisco "clear ip nat translation" helper</title>
<style type="text/css">
body,td,th { color:black;font-family:Verdana; font-size: 8pt }
input, textarea { color:black;font-family:Verdana; font-size: 8pt }
</style>
<script type="text/javascript">
function Do()
{
var sEntries = new String();
sEntries = document.forms['frmMain'].entries.value;
var sVRF = new String();
sVRF = document.forms['frmMain'].vrf.value;
var sReplace;
if ( sVRF == '' )
sReplace = "clear ip nat translation $1 inside $2 $3 $4 $5 outside $6 $7 $8 $9"
else
sReplace = "clear ip nat translation vrf " + sVRF + " $1 inside $2 $3 $4 $5 outside $6 $7 $8 $9";
sEntries = sEntries.replace(/^(tcp|udp)s+(d{1,3}.d{1,3}.d{1,3}.d{1,3}):(d+)s+(d{1,3}.d{1,3}.d{1,3}.d{1,3}):(d+)s+(d{1,3}.d{1,3}.d{1,3}.d{1,3}):(d+)s+(d{1,3}.d{1,3}.d{1,3}.d{1,3}):(d+)/gm, sReplace)
document.forms['frmMain'].result.value = sEntries;
}
</script>
</head>
<body>
<form id=frmMain name=frmMain style="MARGIN:0px" action="#">
<table>
<tr>
<td colspan=2><b>Entries to clear</b></td>
</tr>
<tr>
<td colspan=2>
Paste here the <b>show ip nat translations</b> entries you want to clear:
</td>
</tr>
<tr>
<td colspan=2><textarea wrap=off style="white-space:pre; overflow-x: scroll; overflow-y: scroll" name=entries id=entries cols=100 rows=10></textarea></td>
</tr>
<tr>
<td colspan=2><br></td>
</tr>
<tr>
<td colspan=2><b>VRF aware?</b></td>
</tr>
<tr>
<td colspan=2>
If these entries are part of a vrf, write here the vrf name, otherwise leave this box empty:
</td>
</tr>
<tr>
<td><b>VRF name:</b></td>
<td><input type=text name=vrf id=vrf size=15 value=""></td>
</tr>
<tr>
<td colspan=2><br></td>
</tr>
<tr>
<td colspan=2><b>Results</b></td>
</tr>
<tr>
<td colspan=2><textarea wrap=off style="white-space:pre; overflow-x: scroll; overflow-y: scroll; WIDTH:99%" readonly name=result id=result cols=100 rows=10></textarea></td>
</tr>
<tr>
<td colspan=2><br></td>
</tr>
<tr>
<td colspan=2 align=center><input type=button onclick="Do()" value=" Build clear ip nat translation statements "></td>
</tr>
</table>
</form>
<br>
by Pier Carlo Chiodi - AKA Pierky<br>
<br>
Blog: <a href="http://blog.pierky.com" target="_blank">http://blog.pierky.com</a><br>
Contact me: <a href="http://piercarlochiodi.tel" target="_blank">http://piercarlochiodi.tel</a><br>
</body>
</html>