[Question]
  [
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 `0` or 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 `10`)
**Input**: A string
**Output**: Truthy or Falsey value (arbitrary values also accepted)
**Test Cases**:
```
Input            |  Output  |  Reason
                 |          |
- 1.160.10.240   |  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...)
- 1.2.3.4.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 1.2.3.4)
- 1:1:1:1:1:1:1:1|  false   |  (an IPv6 address, not IPv4)
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged '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).
> 
> 
> 
  
[Answer]
# X86\_64 machine code: ~~18~~ 16 bytes
Edit: This answer doesn't quite work, as
1. I am using `inet_pton` from the standard C libraries, which means I need the extern. I didn't include the extern in my byte count though.
2. I used the red zone as a result for the actual address, but called a function which also could've used the red zone. It fortunately doesn't on my machine, but some odd standard library build might use it which could cause undefined behavior.
And yeah, the whole thing is pretty much being done by an already written function
Anyway, this is what I got: `48 89 fe 6a 02 5f 48 8d 54 24 80 e9 00 00 00 00`
Assembly:
```
section .text
    extern inet_pton
    global ipIsValid
ipIsValid:
    mov rsi, rdi
    ;mov rdi, 2 ; change to 10 for ipv6
    push 2
    pop rdi ; thank you peter
    lea rdx, [rsp - 128]
    jmp inet_pton
```
# Explanation:
Take a look at `inet_pton(3)`. It takes a string IP address and puts it in a buffer you can use with `struct sockaddr`. It takes 3 arguments: the address family (`AF_INET` (ipv4), 2, or `AF_INET6` (ipv6), 10), the ip address's string, and a pointer to the output. It returns 1 on success, 0 for an invalid address, or -1 for when the address family is neither `AF_INET` or `AF_INET6` (which will never occur because I'm passing a constant to it).
So I simply move the string to the register for the second argument, set the first register to 2, and set the third register to the red zone (128 bytes below the stack pointer) since I don't care about the result. Then I can simply `jmp` to `inet_pton` and let that return straight to the caller!
I spun up this quick test program to test your cases:
```
#include <stdio.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
extern int ipIsValid(char *);
int main(){
    char *addresses[] = {
        "1.160.10.240",
        "192.001.32.47",
        "1.2.3.",
        "1.2.3",
        "0.00.10.255",
        "1.2.$.4",
        "255.160.0.34",
        ".1.1.1",
        "1..1.1.1",
        "1.1.1.-0",
        ".1.1.+1",
        "1 1 1 1",
        "1",
        "10.300.4.0",
        "10.4F.10.99",
        "fruit loops",
        "1.2.3.4.5",
        NULL
    };
    for(size_t i = 0; addresses[i] != NULL; ++i){
        printf("Address %s:\t%s\n", addresses[i],
            ipIsValid(addresses[i]) ? "true" : "false");
    }
    return 0;
}
```
Assemble with `nasm -felf64 assembly.asm`, compile with `gcc -no-pie test.c assembly.o`, and you'll get:
```
Address 1.160.10.240:   true
Address 192.001.32.47:  false
Address 1.2.3.: false
Address 1.2.3:  false
Address 0.00.10.255:    false
Address 1.2.$.4:    false
Address 255.160.0.34:   true
Address .1.1.1: false
Address 1..1.1.1:   false
Address 1.1.1.-0:   false
Address .1.1.+1:    false
Address 1 1 1 1:    false
Address 1:  false
Address 10.300.4.0: false
Address 10.4F.10.99:    false
Address fruit loops:    false
Address 1.2.3.4.5:  false
```
I could make this much smaller if the caller was supposed to pass `AF_INET` or `AF_INET6` to the function
[Answer]
# [Java (JDK)](http://jdk.java.net/), 63 bytes
```
s->("."+s).matches("(\\.(25[0-5]|(2[0-4]|1\\d|[1-9])?\\d)){4}")
```
[Try it online!](https://tio.run/##bVJNb9swDL3nVxDGgtlrREiK3dXN0h2GHXoYUKDALkkOiq10yvwRWHKwoclvzyTZTZxtEGSRfI9PpKmt2AuyzX@eVLmrGwNb62NrVIEfZqN/Ypu2yoyqq/@C2jRSlA7atetCZZAVQmv4JlQFryOAPqqNMPbY1yqH0mLhs2lU9bJYgWhedOSpAE@NzFUmjPzUwQ@g9HdRqPzxaR/D/KTJQxhgcKMjLIXJfkgdBuFyiSFPFpQkq0PI7RmvDmy5zA8LRtJV9NmaUfQaH4PoNPO3nK82UpsvQksN874AgIAhu6XIKPKYBhPrp9xG7tDGncuTxBMoTmMPOwA90wVpZzrWYL/pUMpwyjH@2GVynGKf2N3YMy3wDgfqaZqeEy5SeE4QuMYMcw/xKZLEYYw7n/zdDkmQ8OQWCb3uh1w31Hf75jh7GL22hlxCL/bNUOPrwLEFDP7dL4@8rxtgc0aIczwKfnlz4tdATZI7einKFuDHd@wGvKmb/n35Ed9fBh2d57yu60KKChqp28LYBzB4aej4oftEs57@/FsbWWLdGtxZYbMJgzFL9D2M9biyhTjypBfrk44jt4@nPw "Java (JDK) – Try It Online")
## Credits
* -1 byte thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
* [l4m2](https://codegolf.stackexchange.com/users/76323/l4m2) for showing the previously-failing case `.1.1.1.1`.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 43 bytes
```
x=>x.split`.`.map(t=>[t&255]==t&&[])==`,,,`
```
[Try it online!](https://tio.run/##XVBbboMwEPzvKSxUERB4ZRtIgyrzlxP0EyHh8mhT0YDAqjhBD9Aj9iLUdkhiqhXWzM7s4PWH@BJTNZ4Gic993SwtX2aezTAN3UmWUMKnGDzJs1y6LEkKzqXr5oXPeRmGYbk8P@QOBbonQAmwmDghcmjKVOcAqq@pGjMGAlFsZC0AuUrWdx0mhELEIH662BlEoJGKuPxmdSrhEazINE1vA/couA0IeIUKaiOxCHCiNco0x/93wAlgluwBk@0SeLvFuuKVaGx3t8j2YnLHgZ1xtIi6gPVgM10fQZeGu35ElFOMNTFGZMrA0JQV3OADcQpo@/EoqndvQjxDVX@e@q6Brn/zJhhE/SLFKD2a@ChAO/T7/aPOALXe5Pv@8gc "JavaScript (Node.js) – Try It Online")
# [JavaScript (Node.js)](https://nodejs.org), 46 bytes
```
x=>x.split`.`.every(t=>k--&&[t&255]==t,k=4)*!k
```
[Try it online!](https://tio.run/##XVBBbsIwELz3FW5UQVKyK9tJKFFlbrygR4REGkJLg3AUW4h@oA/oE/uR1DYEHLSKNbMzO/H6qzgWqmx3jYaD3FTdVnQnMT@havY7vcY1Vseq/Q61mNcAo9FSj3iWrYTQcS3S6Pmx7l4flgFDNqXIKPKUBjEJWM5NZ4amb6kZcQaKSepkKyDtJe/rhyllmHBMX852jglaZCLOv7k4jfCEXmSe59eBWxReBwp8xxI3TuIJQmY1xi2H@x0gQ@DZFIEOl4DhFpcVe2Kx3x0i3wv0hid@xsIj5gLeg53Y5RFsWTiWLWGCAVjijMSVg7ErL7iCGQ1WuJXtoig/Q0XEnJTyoOS@wr38CBU2xeZNF60OWRaRCRmTv59fc07INlRRFHX/ "JavaScript (Node.js) – Try It Online")
used Arnauld's part
# [JavaScript (Node.js)](https://nodejs.org), ~~54~~ ~~53~~ 51 bytes
```
x=>x.split`.`.every(t=>k--*0+t<256&[~~t]==t,k=4)*!k
```
[Try it online!](https://tio.run/##XVBBboMwELz3FS6qGgjsyjaQBrXmlhf0GEUKJaRNQQGBFdFLjn1An9iPUNshiVOtsGZ3ZgePP7ND1uXtrpGwrzfFsBVDL9Ieu6bayTWusTgU7ZcrRVoCTKkvX3g8e1wej3IlhAxKEXnT@3J4vls6DNmMIqPII@oExGEJV5M5qrlueRwbAcUwMrQmkJ4p6zsvU8ow5Bg9neQcQ9RIWZx@MyoV8YCWZZIkl4WrFV4WMnzDHDeG4iFCrDnGdQ//M0CMoAIj0NsQcJtijHhuNLant8jWAr1i3/ZYWI26gPVgPRsfQZeGk7olTDAA3RghMWVgYMoyLmBOnRVu63aR5R9uR0RK8nrf1VWBVf3udthkm1eZtdJlsUd8MiG/3z/q9MnW7TzPG/4A)
-2B for `0+t<256`, -1B from Patrick Stephansen, +1B to avoid input `1.1.1.1e-80`
RegExp solution ~~58~~54 bytes
```
s=>/^((2(?!5?[6-9])|1|(?!0\d))\d\d?\.?\b){4}$/.test(s)
```
Thank Deadcode for 3 bytes
[Answer]
# [PHP](https://php.net/), 39 36 bytes
```
<?=+!!filter_var($argv[1],275,5**9);
```
[Try it online!](https://tio.run/##K8go@P/fxt5WW1ExLTOnJLUoviyxSEMlsSi9LNowVsfI3FTHVEvLUtP6////hkbmegZAaAgA "PHP – Try It Online")
275 resembles the constant `FILTER_VALIDATE_IP`
5\*\*9 is being used instead of the constant `FILTER_FLAG_IPV4`. This is sufficient, because `5**9 & FILTER_FLAG_IPV4` is truthy, which is exactly what PHP does in the background, as Benoit Esnard pointed out.
Here, `filter_var` returns the first argument, if it's a valid IPv4 address, or false if it's not. With `+!!`, we produce the output required by the challenge.
[Answer]
## PHP, 36 Bytes
```
echo(ip2long($argv[1])===false?0:1);
```
`ip2long` is a well-known [built-in function](http://php.net/manual/en/function.ip2long.php).
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~22~~ ~~21~~ 20 bytes
*-1 byte thanks to Phil H.*
```
{?/^@(^256)**4%\.$/}
```
[Try it online!](https://tio.run/##TYzNDgExFIX3nqKL0pnBmdtfRIQHkZFZ6IqQsZqIZ6@2UuRuvnPynXs/DxcXriObebYLz33bHapOWVc3jZkewdtXePQj8xU/1czfhomQkI4gCcqQWMS8USCS0ApmlQsoaHwpAUUjT6wtE@nWiK@KxmESRiG/J@ick1Kkf063pB/PPz3LJ7bhDQ "Perl 6 – Try It Online")
### Explanation
```
{                  }  # Anonymous Block
  /               /   # Regex match
   ^             $    # Anchor to start/end
    @(    )           # Interpolate
      ^256            #   range 0..255,
                      #   effectively like (0|1|2|...|255)
           **4        # Repeated four times
              %\.     # Separated by dot
 ?                    # Convert match result to Bool
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~26~~ ~~24~~ ~~23~~ ~~22~~ ~~23~~ 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
'.¡DgsAì₅ÝAìÃg4)Ë
```
-1 byte thanks to *@Emigna*.  
+1 byte for bugfixing test case `1.1.1.1E1` incorrectly returning a truthy result.
[Try it online](https://tio.run/##yy9OTMpM/f9fXe/QQpf0YsfDax41tR6eC6QPN6ebaB7u/v/fQM/AQM/QQM/I1BQA) or [verify all test cases](https://tio.run/##XVDBagIxFPyVEApLcd/wkt3o7kGkUL9CelAr0pOgIHpV9OKt9x5671d0/8Qf2SZvV82WEDLzZt4kL6vNdPaxqLf7kVbX86fSo32d4Pf7dbl5qX6uh1P15c/quMyfq0ud1hNtYPoMw7A561RpU1pfKeDrgVrnxMDIcpGDAHGGIjcwuKJ9y2E2yCzyQdNpkaFtbG5snV54QpReluW94RGFe8MUM8zxLpLNQC5oxgZO/8chB7KuD@LuPNQdqJ32RgKOq10Ue4kfuBdnjCPiHxD93U6UZLVWZmiIAhFVyRKYyorSFlSwfvsD).
**Explanation:**
```
'.¡          '# Split the (implicit) input-string on "."
   D          # Duplicate this list
    g         # Pop and push the length of this copy
   s          # Swap so the list is at the top again
    Aì        # Prepend the alphabet before each item
      ₅Ý      # Push a list in the range [0,255]
        Aì    # Prepend the alphabet before each integer here as well
          Ã   # Only keep those items from the first list
           g  # Pop and push its length as well
   4          # Push a 4
    )         # Wrap all three values on the stack into a list
     Ë        # Check that all three are the same (aka all three are 4s)
              # (after which the result is output implicitly)
```
Prepending the alphabet is necessary, because in 05AB1E, `"0"`, `"00"`, `"0e0"`, `"5E0"`, `"-0"` etc. are all the same 'integer' `0`.
[Answer]
# Python 3: ~~81~~ ~~78~~ ~~70~~ ~~69~~ 66 bytes
```
['%d.%d.%d.%d'%(*x.to_bytes(4,'big'),)for x in range(16**8)].count
```
Loop over all possible IPv4 addresses, get the string representation and compare it to the input. It uh... takes a while to run.
EDIT: Removed 3 bytes by switching from full program to anonymous function.
EDIT2: Removed 8 bytes with help from xnor
EDIT3: Removed 1 byte by using an unpacked map instead of list comprehension
EDIT4: Removed 3 bytes by using list comprehension instead of the `ipaddress` module
[Answer]
# PowerShell, ~~59~~ ~~51~~ 49 bytes
*-8 bytes, thanks @AdmBorkBork*
*-2 bytes, `true` or `false` allowed by author*
```
try{"$args"-eq[IPAddress]::Parse($args)}catch{!1}
```
Test script:
```
$f = {
try{"$args"-eq[IPAddress]::Parse($args)}catch{!1}
}
@(
    ,("1.160.10.240" , $true)
    ,("192.001.32.47" , $false)
    ,("1.2.3." , $false)
    ,("1.2.3" , $false)
    ,("0.00.10.255" , $false)
    ,("192.168.1.1" , $true)
    ,("1.2.$.4" , $false)
    ,("255.160.0.34" , $true)
    ,(".1.1.1" , $false)
    ,("1..1.1.1" , $false)
    ,("1.1.1.-0" , $false)
    ,("1.1.1.+1" , $false)
    ,("1 1 1 1" , $false)
    ,("1"            ,$false)
    ,("10.300.4.0"   ,$false)
    ,("10.4F.10.99"  ,$false)
    ,("fruit loops"  ,$false)
    ,("1.2.3.4.5"    ,$false)
) | % {
    $s,$expected = $_
    $result = &$f $s
    "$($result-eq$expected): $result : $s"
}
```
Output:
```
True: True : 1.160.10.240
True: False : 192.001.32.47
True: False : 1.2.3.
True: False : 1.2.3
True: False : 0.00.10.255
True: True : 192.168.1.1
True: False : 1.2.$.4
True: True : 255.160.0.34
True: False : .1.1.1
True: False : 1..1.1.1
True: False : 1.1.1.-0
True: False : 1.1.1.+1
True: False : 1 1 1 1
True: False : 1
True: False : 10.300.4.0
True: False : 10.4F.10.99
True: False : fruit loops
True: False : 1.2.3.4.5
```
Explanation:
The script tries to parse an argument string, to construct a .NET object, [IPAddress](https://docs.microsoft.com/en-us/dotnet/api/system.net.ipaddress.parse).
* return `$true` if `object` created and the argument string is equal to a string representation of the `object` (normalized address by `object.toString()`)
* return `$false` otherwise
## PowerShell, ~~59~~ ~~56~~ 54 bytes, 'don't use a .NET lib' alternative
*-3 bytes, `true` or `false` allowed by author*
*-2 bytes, thanks to @[Deadcode](https://codegolf.stackexchange.com/a/179141/80745) for the cool regexp.*
```
".$args"-match'^(\.(2(?!5?[6-9])|1|(?!0\B))\d\d?){4}$'
```
[Try it online!](https://tio.run/##fZLRToMwFIbveYraVEcjnBQoKCYG44UvIWrIKM4EA1KIJsCz4xlbyNw625vyf/3/c2hbV9@q0RtVlhMryD3pJwosa941dT@zdr1Zvdop2L6dXITJc@TGL3zwBvwS6SPnaZ7mCe/lyFbTaFkPtkVwODb1wIsEeAJ8KShxCGubTvGFxj4I4UHgg7yZcZGV@oCDDwGcAwZdYNxcLQxNLiznRbeATRl6wUgG0mDDsPkvBATy1LdN2@cd9/gP2k5XnEXXRheZp4lQcjCcY4qN47FIENRM5dP2zOKYntKi6T5aUlZVrQ10dz8SQvqnrsXJQC5JP29j2mHqp1brVuX4rNjbTm2U7soWhSt8bUzPImX2XnfV12Lid8tuXGlqjdMv "PowerShell – Try It Online")
Thanks @[Olivier Grégoire](https://codegolf.stackexchange.com/users/16236/olivier-gr%c3%a9goire) for the original regular expression.
[Answer]
# [C (gcc)](https://gcc.gnu.org/) / POSIX, 26 bytes
```
f(s){s=inet_pton(2,s,&s);}
```
[Try it online!](https://tio.run/##TY9fT4MwFMWf6ae4QWfaAdfyZ1PHtq/hw1wMKbA1YYXQ7sWFry62KGruQ3/n5JyTVEQnIcaxpprd9E6qyrx3plU0CXX4oFk@jHdSieZaVrDVppQtnvdEKgOXQirK4EY8cS56WJrDEXZW@jHGa44xxyTjfmj1S4Kcx5gmmD1NBiaY4i854DYxVVaruRKvn9FOzbF7zBzawDTPMZ20i8yh/@wu4n8cfPswncPNhvvEG3Li1W0P1P1I7ngOcqvlR9XW1LDHH1oaZv0gYMTzut4ma@ovNER7WJRvyg/BHOQxBFuxL2N2sq/MtVfAczKMn6JuipMeo1fVRvLSNVJIE9mVLw "C (gcc) – Try It Online")
Works as 64-bit code on TIO but probably requires that `sizeof(int) == sizeof(char*)` on other platforms.
[Answer]
# PHP 7+, ~~37~~ ~~35~~ 32 bytes
This uses the builtin function [`filter_var`](http://php.net/manual/en/function.filter-var.php), to [validate that it is an IPv4 address](http://php.net/manual/en/filter.filters.validate.php).
For it to work, you need to pass the key `i` over a GET request.
```
<?=filter_var($_GET[i],275,5**9);
```
Will output nothing (for a `falsy` result) or the IP (for a `truthy` result), depending on the result.
You can try this on:
~~<http://sandbox.onlinephpfunctions.com/code/639c22281ea3ba753cf7431281486d8e6e66f68e>~~
<http://sandbox.onlinephpfunctions.com/code/ff6aaeb2b2d0e0ac43f48125de0549320bc071b4>
---
This uses the following values directly:
* 275 = FILTER\_VALIDATE\_IP
* ~~1<<20 = 1048576 = FILTER\_FLAG\_IPV4~~
* 5\*\*9 = 1953125 (which has the required bit as "1", for 1048576)
Thank you to [Benoit Esnard](https://codegolf.stackexchange.com/users/38454/benoit-esnard) for this tip that saved me 1 byte!
Thank you to [Titus](https://codegolf.stackexchange.com/users/55735/titus) for reminding me of the changes to the challenge.
---
I've looked into using the function [`ip2long`](http://php.net/manual/en/function.ip2long.php), but it works with non-complete IP addresses.
Non-complete IPv4 addresses are considered invalid in this challenge.
If they were allowed, this would be the final code (only for PHP 5.2.10):
```
<?=ip2long($_GET[i]);
```
Currently, it isn't explicit in the documentation that this will stop working (when passed an incomplete ip) with newer PHP versions.
After testing, confirmed that that was the case.
Thanks to [nwellnhof](https://codegolf.stackexchange.com/users/9296/nwellnhof) for the tip!
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), ~~84~~ ~~79~~ 65 bytes
```
s=>s.Split('.').Sum(t=>byte.TryParse(t,out var b)&t==b+""?1:5)==4
```
[Try it online!](https://tio.run/##dZFBS8QwFITv/opQZDdhdx9Jm1aLpiDCnjwICp63oZVAaJYkFfbX17Te7Ctzex/zYGZ0OOlgpvM46OcQvRm@j6R1zjakV1NQTYBXNw6RatVopWTFlCp2AT6u1kS6hz2DF2tpVE17ix18@tv7xYeOxqMbI/m5eNKyXVSqPWQZm57uvryJ3ZsZOtrTTNQ5cC6gyEE@ZIz9x5BDARv39ZmnXyA45GWJe@5BrgGIWZhhm8w68S1ywDxkEQKQE4ciJZHAUSbPc8i6XsPejyYS69w1bJUpoUSLm7WVB6@g@utaYrY0q6gecWtaZzGnkMsa0y8 "C# (Visual C# Interactive Compiler) – Try It Online")
-5 and -14 bytes saved thanks to @dana!
~~# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 61 bytes~~
```
s=>s.Count(c=>c==46)==3&IPAddress.TryParse(s,out IPAddress i)
```
[Try it online!](https://tio.run/##PcmxCsIwEADQvV8ROkgC9Ui1dKkXEEEQRAoKzpqmEtAEcpehXx@dXN@ztLbkSyYfXuK6ELsPXBwP1TEHuyNOP2/EM8a3ETMWQkNwiDmwtGgsYtcrxO3qNO6nKTkiuKVlfCRykpqYWfxDeFWG6p48u7MPTs6ybqHtNbQaNp2ulSpf "C# (Visual C# Interactive Compiler) – Try It Online")
This is a work in progress. The code use `System.Net` (+17 bytes if you count it). if you wonder why I count and parse:
> 
> The limitation with IPAddress.TryParse method is that it verifies if a string could be converted to IP address, thus if it is supplied with a string value like "5", it consider it as "0.0.0.5".
> 
> 
> 
[source](https://stackoverflow.com/questions/11412956/what-is-the-best-way-of-validating-an-ip-address)
As @milk said in comment, it will indeed fail on leading zeroes. So, the 61 bytes one is not working.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~85 82~~ 81 bytes
-1 byte thanks to Kevin Cruijssen
```
from ipaddress import*
I=input()
try:r=I==str(IPv4Address(I))
except:r=0
print~~r
```
[Try it online!](https://tio.run/##XVDLboMwELz7K6yoEpDWK9sYGipx6KEHbv2FFFyVQ8AyTpVc8uvUDxJMZVma3Zmdfair@RkHPrdjJ3GNd7vd/K3HE@7Vseu0nCbcn9SozR41dT@os0kzZPT1TddNXU9Gp83nr3gP0rTJMiQvrVTG8hQp3Q/mdtOzdUWWkC32bfY4L@dzwoCVFBgFLmiCbFxxmzmAzbuQF4UXUMiFpx0BXumSNECniv7dh1IGOQfxGio55LAUho6L0hJPELlXVfUoWK3gUXCEL2ih8xTPgRSOY9zF5P86pADCixII3e5Dtgst294Dh@PsFsVaQlf8HHt8RIEdILrdxTOjxqxmhDjsSeyfhy/@RWaSHOg6U@gP4aBiva2A5A8 "Python 2 – Try It Online")
[113 byte answer](https://tio.run/##PU/basMwDH3XV4gwsD0yYbtJtwS8x0G@YRs061zmkjrGM6P9@kzNLgiko8uRjtKlfMzRLsu7P@CTHFQPWPKlz@55dxrPUtenEKVt29p/jZMMSqndYc4YMEQc6DNNoUhBQr0C@vPep8JUIQBTDrHIwTlu0nHmJVmpWzn5K3CuUUuICR1WVWXIbDUZTbbRYDrL6QNxccVaG9pYau7BkKUN/YTV31ADmgdWatty7Wpd18H4tgde/CfvJQoF8C@bD/e/AjHU4u5R1MC/B7V8Aw) is deleted as it fails for `1.1.1.1e-80`
[Answer]
# Japt, ~~17~~ 15 bytes
```
q.
Ê¶4«Uk#ÿòs)Ê
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=cS4KyrY0q1VrI//ycynK&input=IjEuMTYwLjEwLjI0MCI=) or [run all test cases](https://ethproductions.github.io/japt/?v=1.4.6&code=cS4KyrY0q1VrI//ycynK&input=WwoiMS4xNjAuMTAuMjQwIgoiMTkyLjAwMS4zMi40NyIKIjEuMi4zLiIKIjEuMi4zIgoiMC4wMC4xMC4yNTUiCiIxLjIuJC40IgoiMjU1LjE2MC4wLjM0IgoiLjEuMS4xIgoiMS4uMS4xLjEiCiIxLjEuMS4tMCIKIi4xLjEuKzEiCiIxIDEgMSAxIgoiMSIKXQotbVI=) or [verify additional test cases from challenge comments](https://ethproductions.github.io/japt/?v=1.4.6&code=cS4KyrY0q1VrI//ycynK&input=WwoiMS4xNjAuMTAuMjQwIgoiMTkyLjE2OC4xLjEiCiIyNTUuMTYwLjAuMzQiCiIxLjEuMS4wIgoiMC4wLjAuMCIKIjI1NS4yNTUuMjU1LjI1NSIKIjE5Mi4wMDEuMzIuNDciCiIxLjIuMy4iCiIwLjAwLjEwLjI1NSIKIjEuMi4kLjQiCiIxLjEuMS45OTkiCiIxLjIuMyIKIjE5Mi4wMC4wLjI1NSIKImEuYi5jLmQiCiIxMjMuLTUwLjAuMTIiCiItMS4xNjAuMTAuMjQwIgoiLTUuLTI1Ni4tMC4xIgoiMjU1LjE2MC4tMC4zNCIKIjEuMS4xLjEuMSIKIjEuMS4xLjEuIgoiLjEuMS4xIgoiMS4uMS4xIgoiMS4uMS4xLjEiCiIxLjEuMS4tMCIKIjEuMS4xLisxIgoiMS4xLjEuMUUxIgoiMS4xLjEuMjU2IgoiMS4xLjEuMHgxIgoiJ29yIDE9MS0tIgoiIgoiMSAxIDEgMSIKIjEsMSwxLDEiCiIxLjEuMS4xZS04MCIKXQotbVI=)
---
## Explanation
We split to an array on `.`, check that the length of that array is equal to `4` AND that the length when all elements in the range `["0","255"]` are removed from it is falsey (`0`).
```
                 :Implicit input of string U
q.               :Split on "."
\n               :Reassign resulting array to U
Ê                :Length of U
 ¶4              :Equals 4?
   «             :&&!
    Uk           :Remove from U
      #ÿ         :  255
        ò        :  Range [0,255]
         s       :  Convert each to a string
          )      :End removal
           Ê     :Length of resulting array
```
[Answer]
# ECMAScript pure regex, 41 bytes
`^((2(?!5?[6-9])|1|(?!0\B))\d\d?\.?\b){4}$`
[Try it online!](https://tio.run/##PY3dToNAEIXv9ylo0oSdKtNdWGooQRKT@gBVr0QTLEtFt0AW6k9/nh13WzXfxZyZM2fmLf/Iu5Wu2t7r2qqQetPU7/J70EktP52lXC@@Wkp3yfV0MjxT6tN0FKaPMy96ggM/mI5lNwBZkRVphmn2AntxHA@T6Q6wb@56XdVrCtipaiXp7NITAHHZaFomPKYq0TIvVFVLCjBK6q1ScZkw2FclHZXQmnBPISbttu96TRVu8n71SjWk7v3yYTF3HHfulrnq5NxxIf5bg/g4cOQzhpyhLxjhkY@McQx8FFeEo48BngthxjitheFpMkZBjD6lGQaCILcY719YPHY2LszAOUEMJmCuCWRWilt7N4pIqbdV76imabvf3wJD@9hiq2OVtQJE8QM "JavaScript (SpiderMonkey) – Try It Online")  
[Try it on regex101](https://regex101.com/r/xFKpgH/1)
I think the logic in this regex speaks for itself, so I will merely pretty-print but not comment it:
```
^
(
    (
        2(?!5?[6-9])
    |
        1
    |
        (?!0\B)
    )
    \d\d?
    \.?\b
){4}
$
```
This can be used to shave 2 bytes off the following other answers:
* [Olivier Grégoire](https://codegolf.stackexchange.com/a/174478/17216) (Java (JDK))
* [l4m2](https://codegolf.stackexchange.com/a/174456/17216) (JavaScript (Node.js))
* [mazzy](https://codegolf.stackexchange.com/a/174483/17216) (PowerShell)
* [Kevin Cruijssen](https://codegolf.stackexchange.com/a/174485/17216) (Retina)
Some alternative 41 byte versions:
`^((2(?!5?[6-9])|1|(?!0\d))\d\d?\.?\b){4}$`  
`^(((2(?!5?[6-9])|1|(?!0))\d)?\d\.?\b){4}$`  
`^(((2(?!5?[6-9])|1)\d|[1-9]?)\d\.?\b){4}$`
Here is an alternative version that allows leading zeros, but does so consistently (octets may be represented by a maximum of 3 decimal digits):
`^((2(?!5?[6-9])|1|0?)\d\d?\.?\b){4}$`
Or allow any number of leading zeros:
`^(0*(2(?!5?[6-9])|1?)\d\d?\.?\b){4}$`
Or if allowed to have undefined behavior regarding leading zeros (as it so happens, a leading zero is only allowed only in 2-digit octets):
`^((2(?!5?[6-9])|1?)\d\d?\.?\b){4}$`
[Answer]
# Mathematica, ~~39~~ 31 bytes
Original version:
```
¬FailureQ[Interpreter["IPAddress"][#]]&
```
Modified version (thanks to Misha Lavrov)
```
 AtomQ@*Interpreter["IPAddress"]
```
which returns `True` if the input is a valid IP address ([try it](https://tio.run/##TY5ND4IwDIb/Clk8@VG7MTTc4GLCDc@EA5EZSeQjY56Mv322U4x50@192q5d37ib6RvXXRpf2m5wlc/d2J@zdTE4Yydr6KxEUeZta808i9rvs@gpJMgDgkRQGsVWyFQBooRYgT4yg4IYFkM3Ujm0J8k3uwJNjjhMQogZQbJCx59l7XApb0IyCmLHQc9pvgb8gD7xrjQlutpH56L7OE7z718aEvGq/Rs)).
In case you insist on getting `1` and `0` instead, then an additional 7 bytes would be necessary:
```
Boole/@AtomQ@*Interpreter["IPAddress"]
```
[Answer]
# JavaScript (ES6), 49 bytes
Returns a Boolean value.
```
s=>[0,1,2,3].map(i=>s.split`.`[i]&255).join`.`==s
```
[Try it online!](https://tio.run/##jZJfa8IwFMXf9ymCyGhZvd78c/QhPu5LiGBxrUSypjR1X79LIjLnaGrOU@DHyT335Fx9V@7Y625YtfazHhs1OrXdYUELVvA9fFVdptXWgeuMHg5w2On9K5Myh7PVrb8r5cajbZ01NRh7yppsQYFuECgCE7jIc0LWazL0l/rlkSsZIFLgDMR7AD3XVMb9B4EBh2h1PUnwjpsE0T8cJ5TyiqcclyB@PadA7xRjI3CRCg006KksD@g0GLTCWTByb3Q@CyVRT4D3u06Cfi1@4wJuUyZA8RGaKct0MU1/0QMx1nZuvkHuX5a3WRN/IuhP6tDg@AM "JavaScript (Node.js) – Try It Online")
[Answer]
# Python 2, ~~93~~ ~~89~~ ~~67~~ 53 bytes
```
[i==`int(i)&255`for i in input().split('.')]!=[1]*4>_
```
[Try it online!](https://tio.run/##TU5dT8MgFH0evwITI63GG6Cg6ZL6tr764tuyuFlZRmwKoTS6X18vzC7m8HHOPede8Od4coOcO/dpaEMZY/PWNs3eDrGw5Z3Uen90gVpqB1x@ikUJo@9tLBiwcnfTbMXuXr28z9hJyPfJ9oa@hcmsySqGM54r82O6Io0vUfiAg3OAoNEZH@nmtd2E4ELKfgRz@Fqc9TXfHvrRzEyAeOIgOEjFGWGilsC5gEqCek4aJFSwELw52jmu9V/1FhQy1HkShypJEAk58Y8mPPLFfshFmpFY2tiO8xXwi1BtequuUR3DZCPtnfPj9V8K9OVLCYz8Ag "Python 2 – Try It Online")
Thanks to Dennis for shaving *another* 14 bytes on the internal comparisons and exit code.
Special thanks to Jonathan Allan for shaving 22 bytes & a logic fix! Pesky try/except begone!
Taking properly formatted strings instead of raw bytes shaves off 4 bytes, thanks Jo King.
[Answer]
# [sfk](http://stahlworks.com/dev/swiss-file-knife.html), 176 bytes
\* was originally Bash + SFK but TIO has since added a proper SFK wrapper
```
xex -i "_[lstart][1.3 digits].[1.3 digits].[1.3 digits].[1.3 digits][lend]_[part2]\n[part4]\n[part6]\n[part8]_" +xed _[lstart]0[digit]_999_ +hex +linelen +filt -+1 -+2 +linelen
```
[Try it online!](https://tio.run/##jY7BCsMgEER/Zcl1iagJpX6LXZaCppWKlOrBv7dLIDnnMPB2YGembp8xeuwwJ5jY59qev0beqAVCeqVWSV07fI4lEPuv/Ft6lB3WA24H3IknwB4DnGXa7xHEzjkGfMsYzKlECQTcUm4woxHZ0x7DOKu0lnqrVv0H "sfk – Try It Online")
[Answer]
# ~~Python3~~ Bash\* 60
\*Also other shells. Any one for which the [truthy/falsy](https://codegolf.meta.stackexchange.com/a/2194/25088) test passes on a program exit code
```
read I
python3 -c "from ipaddress import*;IPv4Address('$I')"
```
## Explanation
The trouble with a pure Python solutions is that a program crashing is considered indeterminate. We could use a "lot" of code to convert an exception into a proper truthy/fasly value. However, at some point the Python interpreter handles this uncaught exception and returns a non-zero exit code. For the low-low cost of changing languages to your favourite Unix shell, we can save quite a bit of code!
Of course, this is vulnerable to injection attacks... Inputs such as `1.1.1.1'); print('Doing Something Evil` are an unmitigated threat!
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 15 bytes
```
ipcalc -c `cat`
```
[Try it online!](https://tio.run/##S0oszvj/P7MgOTEnWUE3WSEhObEk4f9/Qz1DMwM9I1NzIDYDAA "Bash – Try It Online")
Outputs exit code 0 for truthy, 1 for falsy.
[Answer]
# [Red](http://www.red-lang.org), 106 bytes
```
func[s][if error? try[t: load s][return off]if 4 <> length? t[return off]s =
form as-ipv4 t/1 t/2 t/3 t/4]
```
[Try it online!](https://tio.run/##XY7JDoMwDETvfIWFeq2bjS6oyz/0GnFAJWmRaIJMqNSvTyMujTjMwW9mbJPp4t10uilsHe3sHnpqdG/BEHm6QaCvDjUMvu0gGWTCTA68tU3KKDhfYTDuGV4pmZsTXArr6Q3ttO3Hj4Kw40kiSSapJo7UuwAWSo58z5AzFIqVxR@fBDLGUQpUh5yjQIlrkM0s1ZZ1VbVax/dHTNdW3Q2qjIhqeYehVGX8AQ "Red – Try It Online")
Returnd `true` or `false`
## Explanation:
```
f: func [ s ] [
    if error? try [                  ; checks if the execution of the next block result in an error
        t: load s                    ; loading a string separated by '.' gives a tuple   
    ] [                              ; each part of which must be in the range 0..255
        return off                   ; if there's an error, return 'false' 
    ]
    if 4 <> length? t [              ; if the tuple doesn't have exactly 4 parts
        return off                   ; return 'false'  
    ]
    s = form as-ipv4 t/1 t/2 t/3 t/4 ; is the input equal to its parts converted to an IP adress
]
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 14 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
∞n·Θ3ª&JH‼∙*~Γ
```
[Run and debug it](https://staxlang.xyz/#p=ec6efae933a6264a4813f92a7ee2&i=%221.160.10.240%22%0A%22192.001.32.47%22%0A%221.2.3.%22%0A%221.2.3%22%0A%220.00.10.255%22%0A%221.2.%24.4%22%0A%22255.160.0.34%22%0A%22.1.1.1%22%0A%221..1.1.1%22%0A%221.1.1.-0%22%0A%22.1.1.%2B1%22%0A%221+1+1+1%22%0A%221%22%0A%2210.300.4.0%22%0A%2210.4F.10.99%22%0A%22fruit+loops%22%0A%221.2.3.4.5%22&a=1&m=2)
Unpacked, ungolfed, and commented, it looks like this.
```
VB      constant 256
r       [0 .. 255]
'|*     coerce and string-join with "|"; i.e. "0|1|2|3 ... 254|255"
:{      parenthesize to "(0|1|2|3 ... 254|255)"
]4*     make 4-length array of number pattern
.\.*    string join with "\\."; this forms the complete regex
|Q      is the input a complete match for the regex?
```
[Run this one](https://staxlang.xyz/#c=VB++%09constant+256%0Ar+++%09[0+..+255]%0A%27%7C*+%09coerce+and+string-join+with+%22%7C%22%3B+i.e.+%220%7C1%7C2%7C3+...+254%7C255%22%0A%3A%7B++%09parenthesize+to+%22%280%7C1%7C2%7C3+...+254%7C255%29%22%0A]4*+%09make+4-length+array+of+number+pattern%0A.%5C.*%09string+join+with+%22%5C%5C.%22%3B+this+forms+the+complete+regex%0A%7CQ++%09is+the+input+a+complete+match+for+the+regex%3F&i=%221.160.10.240%22%0A%22192.001.32.47%22%0A%221.2.3.%22%0A%221.2.3%22%0A%220.00.10.255%22%0A%221.2.%24.4%22%0A%22255.160.0.34%22%0A%22.1.1.1%22%0A%221..1.1.1%22%0A%221.1.1.-0%22%0A%22.1.1.%2B1%22%0A%221+1+1+1%22%0A%221%22%0A%2210.300.4.0%22%0A%2210.4F.10.99%22%0A%22fruit+loops%22%0A%221.2.3.4.5%22&a=1&m=2)
[Answer]
# Python 3, ~~109~~ 93 bytes
```
import re
lambda x:bool(re.match(r'^((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(\.(?!$)|$)){4}$',x))
```
**Explanation**  
Each octet can be 0 - 255 :
* starts with 25 and having 0-5 as last digit
* start with 2, has 0-4 as second digit and any digit at the end
* starts with 1, and 00 - 99 as rest digits
* has only 2 digits - 1-9 being the first one and any digit thereafter
* or just a single digit
An octet can end with a (.) or just end, with the condition that it cannot do both , the negative lookahead `(?!$)` takes care of this case
Thanks [@Zachary](https://codegolf.stackexchange.com/users/55550/zachar%C3%BD) for making me realize I can discard spaces (since it is code golf)   
Thanks [@DLosc](https://codegolf.stackexchange.com/users/16766/dlosc) for the improvements and making me realize my mistake, its been corrected now.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~45~~ 21 bytes
```
Ｉ∧⁼№θ.³¬Φ⪪θ.¬№Ｅ²⁵⁶Ｉλι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEwzEvRcO1sDQxp1jDOb8UKFqoo6Ckp6Spo2AMxH75JRpumTklqUUawQU5mUiyIBmIBt/EAg0jUzMdBbB5OZpAyUxNCLD@/99Az8BAz9BAz8jU9L9uWQ4A "Charcoal – Try It Online") Link is to verbose version of code. Edit: Saved 24 bytes by porting @Shaggy's Japt answer. Explanation:
```
    θ                   Input string
   №                    Count occurrences of
     .                  Literal `.`
  ⁼                     Equal to
      ³                 Literal 3
 ∧                      Logical And
       ¬                Logical Not
          θ             Input string
         ⪪              Split on
           .            Literal `.`
        Φ               Filter by
            ¬           Logical Not
               ²⁵⁶      Literal 256
              Ｅ         Map over implicit range
                   λ    Map value
                  Ｉ     Cast to string
             №          Count occurrences of
                    ι   Filter value
Ｉ                       Cast to string
                        Implicitly print
```
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki), ~~46~~ 44 bytes
```
^
.
^(\.(25[0-5]|(2[0-4]|1\d|[1-9])?\d)){4}$
```
Port of [*@OlivierGrégoire*'s Java answer](https://codegolf.stackexchange.com/a/174478/52210), so make sure to upvote him!  
-2 bytes thanks to *@Neil*.
[Try it online](https://tio.run/##VVDBTsMwDL37K3YYohX4yXaTbTkgToiPWDux0R24MGnigET59pKkS1VkRbGf37Nfcj1/fXwedbyrXt/GA4EOVYvK/F7Yd0Nl8XbdoG0/7JVDVz@3fV3/uN/1OCp0I1CBOSENFssdIkjmfW4JGkeaIAilMkZuLk4Wiigag9tGtqFBIk@TEyFCa5RBIYSJdBNiIh1xwjt6UmvAPqFqxP8csgeb34BlYZEXHpP1ktFcL665z3JLHmbFS8niivLmb6X7y3WlT8pMpKscpI85ivDMO6F5P6YPcH8).
**Explanation:**
```
^
.                           # Prepend a dot "." before the (implicit) input
^...$                       # Check if the entire string matches the following regex
                            # exactly, resulting in 1/0 as truthy/falsey:
 (                          #  Open a capture group
  \.                        #   A dot "."
    (25[0-5]                #   Followed by a number in the range [250,255]
    |(2[0-4]|         ) \d) #   or by a number in the range [200,249]
    |(      |1\d|     ) \d) #   or by a number in the range [100,199]
    |(          |[1-9]) \d) #   or by a number in the range [10,99]
    |(                )?\d) #   or by a number in the range [0,9]
 )                          #  Close capture group
  {4}                       #  This capture group should match 4 times after each other
```
[Answer]
# [Perl 5](https://www.perl.org/) `-pF/\./`, 47 bytes
```
$\=@F==4&&!/[^0-9.]/;$\&&=!/^0./&&$_<256for@F}{
```
[Try it online!](https://tio.run/##K0gtyjH9/18lxtbBzdbWRE1NUT86zkDXUi9W31olRk3NVlE/zkBPX01NJd7GyNQsLb/Iwa22@v9/Qz0DINIz/JdfUJKZn1f8X9fXFChk8F@34L@um36Mnj4A "Perl 5 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
⁹ḶṾ€ṗ4j€”.ċ
```
A monadic link accepting a list of characters which yields \$1\$ if it's a valid address and \$0\$ otherwise. Builds a list of all \$256^4=4294967296\$ addresses and then counts the number of occurrences of the input therein.
**[Here's similar @ Try it online!](https://tio.run/##y0rNyan8//9R45aHO7Y93LnvUdOahzunm2QB6UcNc/WOdP///1/J0FTPQM9Qz9BACQA "Jelly – Try It Online")** that uses \$16\$ (`⁴`) rather than \$256\$ (`⁹`), since the method is so inefficient!
### How?
```
⁹ḶṾ€ṗ4j€”.ċ - Link: list of characters, S
⁹           - literal 256
 Ḷ          - lowered range = [0,1,2,...,254,255]
  Ṿ€        - unevaluate €ach = ['0','1',...,['2','5','4'],['2','5','5']]
    ṗ4      - 4th Cartesian power = ALL 256^4 lists of 4 of them
            -               (e.g.: ['0',['2','5','5'],'9',['1','0']])
        ”.  - literal '.' character
      j€    - join for €ach (e.g. ['0','.','2','5','5','.','9','.','1','0'] = "0.255.9.10")
          ċ - count occurrences of right (S) in left (that big list)
```
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~42~~ 41 bytes
```
~(K`
255*
["^(("|'|]")\.?\b){4}$"L$`
$.`
```
[Try it online!](https://tio.run/##VVBNb8IwDL37V6CqiALzk50mQA/TTogD/IOxqXwduICEdpg02F/vkpRUnawo9vN79ktup6/zZafNsFjVzW@xromMcxN6zz6LIruP7h/ZeIu37X78Yx95tslrylE3jUJnAhUYK6SV8eUCHgzq2BKUljRAEAqlj9jsnSgUUZQGdu7ZBiUCuZ0cCB7KkQZVVdWSnkK0pB32OOBIakqwC6ga4n8O2YGNm4GlZ5F7HoP1lFFX966uz/JMpp1imTK/Ir35W2l0vQ30VZmJdBCD9CVGEp54IdTtR/sB9g8 "Retina – Try It Online") Based on a previous version of @nwellnhof's Perl 6 answer, but 1 byte saved by stealing the `\.?\b` trick from @Deadcode's answer. Explanation:
```
K`
```
Clear the work area.
```
255*
```
Insert 255 characters.
```
["^(("|'|]")\.?\b){4}$"L$`
$.`
```
Generate the range 0..255 separated with `|`s, prefixed with `^((`, and suffixed with `)\.?\b){4}$`, thus building the regular expression `^((0|1|...255)\.?\b){4}$`.
```
~(
```
Evaluate that on the original input.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~25~~ 16 bytes
```
a~=X,256RL4J"\."
```
Takes the candidate IP address as a command-line argument. [Try it online!](https://tio.run/##K8gs@P8/sc42QsfI1CzIx8RLKUZP6f///4Z6hmYGeoYGekYmBgA "Pip – Try It Online") or [Verify all test cases](https://tio.run/##TU7LCsIwELz3K8LiTTts0qSlBz16EL14ElTEi1AotPg4if56zKYPy5AwM8zuTlu1/gJS6UoR3v76XR4WxuX7rd3QCeQ/aqeOiSINnTM0w1gm0aUBs0ZmYItowCDDyIRwSMQR5wZ/Bis0OHEfI4saWtCFplyQ8piYd7aKiDR@YUs4ZMG9smu5WpYib/dX9VR107SPf0sLN7SYvL6ygJKz92n9Aw)
### Explanation
Regex solution, essentially a port of [recursive's Stax answer](https://codegolf.stackexchange.com/a/174518/16766).
```
                  a is 1st cmdline arg (implicit)
    ,256          Range(256), i.e. [0 1 2 ... 255]
   X              To regex: creates a regex that matches any item from that list
                  i.e. essentially `(0|1|2|...|255)`
        RL4       Create a list with 4 copies of that regex
           J"\."  Join on this string
 ~=               Regex full-match
a                 against the input
```
]