mirror of
https://github.com/thegeeklab/prometheus-pve-sd.git
synced 2024-06-02 16:09:41 +02:00
Improve ipv4 validation
- Use builtin ipaddress module for validation - Ensure to exclude the whole loopback network
This commit is contained in:
parent
233af09bd4
commit
2fd4031e21
|
@ -3,7 +3,7 @@
|
|||
|
||||
import json
|
||||
import re
|
||||
import socket
|
||||
import ipaddress
|
||||
from collections import defaultdict
|
||||
|
||||
import requests
|
||||
|
@ -89,12 +89,9 @@ class Discovery():
|
|||
|
||||
def validate_ipv4(address: object) -> object:
|
||||
try:
|
||||
# IP address validation
|
||||
if socket.inet_aton(address):
|
||||
# Ignore localhost
|
||||
if address != "127.0.0.1":
|
||||
return address
|
||||
except socket.error:
|
||||
if ipaddress.ip_address(address) not in ipaddress.ip_network("127.0.0.0/8"):
|
||||
return address
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
address = False
|
||||
|
|
Loading…
Reference in New Issue
Block a user