check_ipv4.py.in 435 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!%(python_path)s
# BEWARE: This file is operated by slapgrid
# BEWARE: It will be overwritten automatically
import socket

address = "%(value)s"

try:
  socket.inet_pton(socket.AF_INET, address)
except AttributeError:  # no inet_pton here, sorry
  try:
    socket.inet_aton(address)
  except socket.error:
    sys.exit(127)
  if address.count('.') != 3:
    sys.exit(127)

except socket.error:  # not a valid address
   sys.exit(127)