Skip to main content
1 of 4
Sompom
  • 221
  • 1
  • 6

#Python3 Bash* 60

*Also other shells. Any one for which the truthy/falsy test passes on a program exit code

read I
python3 -c "from ipaddress import*;IPv4Address('$I')"

Explaination

The trouble with a lot of the Python solutions thus-far posted is that a program crashing is considered indeterminate, so they have to 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!

Sompom
  • 221
  • 1
  • 6