git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Pfeiffer <coding _ lirion.de> 2020-07-30 08:54:15 +0200
committerHarald Pfeiffer <coding _ lirion.de> 2020-07-30 08:54:15 +0200
commit9f5e27f04a2083cedc374d4eda1820a7c41a4b25 (patch)
treec019763861a936bc93a2b9214ebd2c91d3c1a544
parentca8fbea302e20faa540dcc61873a7aaefee4665f (diff)
downloadlinux-scripts-9f5e27f04a2083cedc374d4eda1820a7c41a4b25.tar.bz2
ip4inc
-rw-r--r--bin/ip4inc50
1 files changed, 50 insertions, 0 deletions
diff --git a/bin/ip4inc b/bin/ip4inc
new file mode 100644
index 0000000..7e427ae
--- /dev/null
+++ b/bin/ip4inc
@@ -0,0 +1,50 @@
+#!/usr/bin/gawk -f
+
+# Very small awk snippet to increase the last octet of an IPv4 address by 1.
+# Paradigm: This increases x.x.x.254 and x.x.x.255 to x.x.(x+1).1, as in most cases,
+# x.x.x.0 and x.x.x.255 are reserved (in networks greater or equal /30).
+# Input is STDIN: Either call the script and type addresses, or pipe addresses
+# into it.
+# Reads from STDIN using gawk.
+# LICENSE: GPLv3
+# AUTHOR: Harald Pfeiffer <coding@lirion.de>
+
+
+BEGIN { FS="." }
+{
+ $1 ~ /^[0-9]+$/
+ if ( $4 >= 256 ) {
+ print "Not an IP: "$1"."$2"."$3"."$4;
+ }
+ else if ( $1 >= 256 ) {
+ print "Not an IP: "$1"."$2"."$3"."$4;
+ }
+ else if ( $2 >= 256 ) {
+ print "Not an IP: "$1"."$2"."$3"."$4;
+ }
+ else if ( $3 >= 256 ) {
+ print "Not an IP: "$1"."$2"."$3"."$4;
+ }
+ else {
+ if ( $4 < 254 ) {
+ $4 = $4+1;
+ }
+ else if ( $3 < 254 ) {
+ $3 = $3+1;
+ $4 = 1;
+ }
+ else if ($2 < 254 ) {
+ $2 = $2+1;
+ $3 = 1;
+ $4 = 1;
+ }
+ else if ($1 < 254 ) {
+ $1 = $1+1;
+ $2 = 1;
+ $3 = 1;
+ $4 = 1;
+ }
+ else { print "cannot be incremented!" >/dev/stderr }
+ print $1"."$2"."$3"."$4
+ }
+}