Your network scanning tool is annoyingly picky about input, and immediately crashes if you feed it an IPv4 address that contains improper characters or isn't properly formatted.
An IPv4 address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.
We need to write a tool to pre-validate the input to avoid those crashes, and our specific tool is picky: A valid format will look like
a.b.c.d where a, b, c and d:
- Can be a
0or a natural number with no leading zeros.
- Should be between 0 - 255 (inclusive).
- Should not contain special symbols like
,, and others.
- Should be decimal (base
Input: A string
Output: Truthy or Falsey value (arbitrary values also accepted)
Input | Output | Reason | | - 22.214.171.124 | true | - 192.001.32.47 | false | (leading zeros present) - 1.2.3. | false | (only three digits) - 1.2.3 | false | (only three digits) - 0.00.10.255 | false | (leading zeros present) - 1.2.$.4 | false | (only three digits and a special symbol present) - 255.160.0.34 | true | - .1.1.1 | false | (only three digits) - 1..1.1.1 | false | (more than three periods) - 1.1.1.-0 | false | (special symbol present) - .1.1.+1 | false | (special symbol present) - 1 1 1 1 | false | (no periods) - 1 | false | (only one digit) - 10.300.4.0 | false | (value over 255) - 10.4F.10.99 | false | (invalid characters) - fruit loops | false | (umm...) - 126.96.36.199.5 | false | (too many periods/numbers) - 0.0.0.0 | true | - 0.0 0.0. | false | (periods misplaced) - 1.23..4 | false | (a typo of 188.8.131.52) - 1:1:1:1:1:1:1:1| false | (an IPv6 address, not IPv4)
This is code-golf, so fewest bytes will win!
Note for the users - if anyone wants to add some test-cases, they're welcomed (by suggesting an edit).