- Products
- Learn
- Local User Groups
- Partners
- More
Welcome to Maestro Masters!
Talk to Masters, Engage with Masters, Be a Maestro Master!
Join our TechTalk: Malware 2021 to Present Day
Building a Preventative Cyber Program
Be a CloudMate!
Check out our cloud security exclusive space!
Check Point's Cyber Park is Now Open
Let the Games Begin!
As YOU DESERVE THE BEST SECURITY
Upgrade to our latest GA Jumbo
CheckFlix!
All Videos In One Space
If we have some dyn object with range like 10.10.10.0 - 10.10.10.20. And we want to delete ip 10.10.10.10 from this range, we need to delete manual whole range 10.10.10.0-10.10.10.20 from our dynamic object and after that add two other ranges into this object. Script just simplify this routine. We just need edit two environment variables: DYN_OBJ and FIND_IP.
export DYN_OBJ="dyn_obj_name"; export FIND_IP="10.10.10.10"; dynamic_objects -l | sed -n '/'"$DYN_OBJ"'/,/^$/p' | awk -v DYN_OBJ="$DYN_OBJ" -v FIND_IP="$FIND_IP"
'
function ip2dec(str){
split(str, octets, ".");
dec=0;
for (i = 1; i <= 4; i++) {
dec += octets[i] * 256 ** (4 - i);
}
return dec;
}
function dec2ip(dec){
ip = "";
delim = "";
for (e = 3; e >= 0; e--) {
octet = int(dec / (256 ^ e));
dec -= octet * 256 ^ e;
ip = ip delim octet;
delim = ".";
}
return ip;
}
NR>2 {
if( ip2dec($4) <= ip2dec(FIND_IP) && ip2dec(FIND_IP) <= ip2dec($5) ) {print $4 " " $5; cmd="dynamic_objects -o " DYN_OBJ" -r " $4 " " $5 " -d"; print cmd; system(cmd);}
if( ip2dec($4) == ip2dec(FIND_IP) && ip2dec(FIND_IP) == ip2dec($5) ) { print "already deleted"};
if( ip2dec($4) == ip2dec(FIND_IP) && ip2dec(FIND_IP) < ip2dec($5) ) { cmd="dynamic_objects -o " DYN_OBJ" -r " dec2ip(ip2dec(FIND_IP)+1) " " $5 " -a"; print cmd; system(cmd);}
if( ip2dec($4) < ip2dec(FIND_IP) && ip2dec(FIND_IP) == ip2dec($5) ) { cmd="dynamic_objects -o " DYN_OBJ" -r " $4 " " dec2ip(ip2dec($5)-1) " -a"; print cmd; system(cmd);};
if( ip2dec($4) < ip2dec(FIND_IP) && ip2dec(FIND_IP) < ip2dec($5) ) { cmd="dynamic_objects -o " DYN_OBJ" -r " $4 " " dec2ip(ip2dec(FIND_IP)-1) " -a"; print cmd; system(cmd);cmd="dynamic_objects -o " DYN_OBJ" -r " dec2ip(ip2dec(FIND_IP)+1) " " $5 " -a"; print cmd; system(cmd);};
}
'
And all of it as `on-liner` for directly usage from CLI (run it from expert-mode)
export DYN_OBJ="dyn_obj_name"; export FIND_IP="10.10.10.10"; dynamic_objects -l | sed -n '/'"$DYN_OBJ"'/,/^$/p' | awk -v DYN_OBJ="$DYN_OBJ" -v FIND_IP="$FIND_IP" ' function ip2dec(str){ split(str, octets, "."); dec=0; for (i = 1; i <= 4; i++) { dec += octets[i] * 256 ** (4 - i); } return dec; } function dec2ip(dec){ for (e = 3; e >= 0; e--) { octet = int(dec / (256 ^ e)); dec -= octet * 256 ^ e; ip = ip delim octet; delim = "."; } return ip; } NR>2 { if( ip2dec($4) <= ip2dec(FIND_IP) && ip2dec(FIND_IP) <= ip2dec($5) ) {print $4 " " $5; cmd="dynamic_objects -o " DYN_OBJ" -r " $4 " " $5 " -d"; print cmd; system(cmd);} if( ip2dec($4) == ip2dec(FIND_IP) && ip2dec(FIND_IP) == ip2dec($5) ) { print "already deleted" }; if( ip2dec($4) == ip2dec(FIND_IP) && ip2dec(FIND_IP) < ip2dec($5) ) { cmd="dynamic_objects -o " DYN_OBJ" -r " dec2ip(ip2dec(FIND_IP)+1) " " $5 " -a"; print cmd; system(cmd);} if( ip2dec($4) < ip2dec(FIND_IP) && ip2dec(FIND_IP) == ip2dec($5) ) { cmd="dynamic_objects -o " DYN_OBJ" -r " $4 " " dec2ip(ip2dec($5)-1) " -a"; print cmd; system(cmd);}; if( ip2dec($4) < ip2dec(FIND_IP) && ip2dec(FIND_IP) < ip2dec($5) ) { cmd="dynamic_objects -o " DYN_OBJ" -r " $4 " " dec2ip(ip2dec(FIND_IP)-1) " -a"; print cmd; system(cmd);cmd="dynamic_objects -o " DYN_OBJ" -r " dec2ip(ip2dec(FIND_IP)+1) " " $5 " -a"; print cmd; system(cmd);}; }'
Because it is not a script-file. It's a one-liner. 🙂 We have many appliances and I don't want to copy file on each. So I preferred one-liners which I just can copy in console.
I added more readable version of code into thread main message
About CheckMates
Learn Check Point
Advanced Learning
YOU DESERVE THE BEST SECURITY