{"id":1,"date":"2014-08-13T13:30:43","date_gmt":"2014-08-13T13:30:43","guid":{"rendered":"http:\/\/iict-space.heig-vd.ch\/mri\/?p=1"},"modified":"2014-09-25T09:48:31","modified_gmt":"2014-09-25T09:48:31","slug":"hello-world","status":"publish","type":"post","link":"http:\/\/iict-space.heig-vd.ch\/mri\/2014\/08\/13\/hello-world\/","title":{"rendered":"Validate IP Addresses and Slash Notation"},"content":{"rendered":"<p><span style=\"color: #373737\">I\u2019m currently working on a project that requires the user to provide a target IPv4 address within a LAN for a network analysis. The address may indicate a single host (i.e. 10.0.2.25) or it may use \u201cslash notation\u201d to designate a group of IP addresses according to the\u00a0<\/span><a style=\"color: #1982d1\" href=\"http:\/\/www.ripe.net\/internet-coordination\/press-centre\/understanding-ip-addressing\" target=\"_blank\">Classless Inter-Domain Routing (CIDR) Chart<\/a><span style=\"color: #373737\">\u00a0(i.e. 10.0.2.0\/24):<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone\" src=\"http:\/\/rubinstein.me\/wp-content\/uploads\/2013\/01\/cidr_chart-2.jpg\" alt=\"\" width=\"354\" height=\"495\" \/><\/p>\n<p style=\"color: #373737\">Google found several regular expressions that were supposed to filter out valid IP addresses but none of them included the slash notation, and many of them didn\u2019t even work correctly.<\/p>\n<p style=\"color: #373737\">I finally decided to write my own from scratch and put it all in a function to determine if an IP address (or network) is valid. I believe it works as expected:<\/p>\n<p><a href=\"http:\/\/iict-space.heig-vd.ch\/mri\/wp-content\/uploads\/sites\/3\/2014\/08\/code.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-14\" src=\"http:\/\/iict-space.heig-vd.ch\/mri\/wp-content\/uploads\/sites\/3\/2014\/08\/code-300x105.png\" alt=\"code\" width=\"541\" height=\"203\" \/><\/a><br \/>\nLet me know if this helps you!You may freely use this code if you wish, but I\u2019m not officially releasing it under any open source license because I need my other code that integrates this to remain closed source.<\/p>\n<p><strong>Update<\/strong>: Found a little bug and corrected it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m currently working on a project that requires the user to provide a target IPv4 address within a LAN for a network analysis. The address may indicate a single host (i.e. 10.0.2.25) or it may use \u201cslash notation\u201d to designate <a class=\"more-link\" href=\"http:\/\/iict-space.heig-vd.ch\/mri\/2014\/08\/13\/hello-world\/\">Continue reading <span class=\"screen-reader-text\">  Validate IP Addresses and Slash Notation<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[9,10,12,11],"_links":{"self":[{"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/posts\/1"}],"collection":[{"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":3,"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":16,"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/posts\/1\/revisions\/16"}],"wp:attachment":[{"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iict-space.heig-vd.ch\/mri\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}