check ip address code example
Example 1: Validate IP Address
try:
if len(IP.split('.')) == 4:
print(IP)
if all([bool(1) if(str(int(s)) == s and 0 <= int(s) <= 255) else bool(0) for s in IP.split('.')]):
return "IPv4"
if len(IP.split(':')) == 8:
if all([bool(1) if(len(s) <= 4 and int(s, 16) >= 0) else bool(0) for s in IP.split(':')]):
return "IPv6"
except:
return "Neither"
return "Neither"
Example 2: how to find ip address
import java.net.InetAddress;
import java.net.UnknownHostException;
public class FindIPaddress {
public static void main(String[] args) throws UnknownHostException {
InetAddress a = InetAddress.getLocalHost();
System.out.println(a.getHostAddress());
}
}
Example 3: my ip
Only Share This if you are hosting a server or something and you know what ur doing.