擅长:python、mysql、java
<p>如果您想确保IP是正确的,您可以使用另一个答案中建议的regex从url中提取它,然后验证您可以使用<a href="https://netaddr.readthedocs.org/en/latest/" rel="nofollow">netaddr</a>它使用起来相当简单。在</p>
<pre><code>from netaddr import IP, AddrFormatError
ip = extract_ip_from_url(url)
try:
IP(ip)
return True
except AddrFormatError:
return False
</code></pre>