{"id":393,"date":"2019-07-13T13:03:41","date_gmt":"2019-07-13T11:03:41","guid":{"rendered":"http:\/\/catyellow.net\/blog\/?p=393"},"modified":"2019-07-13T13:03:41","modified_gmt":"2019-07-13T11:03:41","slug":"how-to-find-unused-ip-in-subnetwork","status":"publish","type":"post","link":"https:\/\/catyellow.net\/blog\/?p=393","title":{"rendered":"How to find unused IP in subnetwork"},"content":{"rendered":"\n<p>Working with many docker containers on one machine I needed to get list of free IP addresses in specific docker network. This is the way:<\/p>\n\n\n\n<p><br><\/p>\n\n\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncomm -3 &lt;(nmap -sL 172.30.0.10\/29 | awk '\/Nmap scan report\/{print $NF}' | sort) &lt;(nmap -sn 172.30.0.10\/29 | awk '\/Nmap scan report\/{print $NF}' | sort) | sort -V\n172.30.0.9\n172.30.0.10\n172.30.0.11\n172.30.0.12\n172.30.0.13\n172.30.0.14\n172.30.0.15\n<\/pre>\n\n\n<p>Let me explain.<\/p>\n\n\n\n<p>This generates the list of IPs in subnetwork:<\/p>\n\n\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nnmap -sL 172.30.0.10\/29 | awk '\/Nmap scan report\/{print $NF}'\n172.30.0.8\n172.30.0.9\n172.30.0.10\n172.30.0.11\n172.30.0.12\n172.30.0.13\n172.30.0.14\n172.30.0.15\n<\/pre>\n\n\n<p>This generates list of used IPs in subnetwork:<\/p>\n\n\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nnmap -sn 172.30.0.10\/29 | awk '\/Nmap scan report\/{print $NF}' \n172.30.0.8\n<\/pre>\n\n\n<p>The comm compares two lists and suppress common lines<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncomm - compare two sorted files line by line\n       -3     suppress column 3 (lines that appear in both files)\n<\/pre>\n\n\n<p>One more example:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncat ip_pool.txt\n172.30.0.8\n172.30.0.9\n172.30.0.10\n172.30.0.11\n172.30.0.12\n172.30.0.13\n172.30.0.14\n172.30.0.15\n\ncat ip_used.txt\n172.30.0.8\n172.30.0.10\n\ncomm -3 &lt;(cat ip_pool.txt | sort) &lt;(cat ip_used.txt | sort) | sort -V\n172.30.0.9\n172.30.0.11\n172.30.0.12\n172.30.0.13\n172.30.0.14\n172.30.0.15\n<\/pre>\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with many docker containers on one machine I needed to get list of free IP addresses in specific docker network. This is the way: Let me explain. This generates the list of IPs in subnetwork: This generates list of used IPs in subnetwork: The comm compares two lists and suppress common lines One more [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/393"}],"collection":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=393"}],"version-history":[{"count":3,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/393\/revisions"}],"predecessor-version":[{"id":396,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/393\/revisions\/396"}],"wp:attachment":[{"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/catyellow.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}