Checking for IP addresses

后端 未结 8 2064
闹比i
闹比i 2020-12-18 00:03

Are there any existing libraries to parse a string as an ipv4 or ipv6 address, or at least identify whether a string is an IP address (of either sort)?

8条回答
  •  眼角桃花
    2020-12-18 00:39

    If you know for sure that the address is valid and only trying to decide whether it is ipv4 or ipv6, wouldn't it be sufficient to do just:

    if ":" in address:
        print("Ipv6")
    else:
        print("Ipv4")
    

提交回复
热议问题