Regex to match an IP address [closed]

Don’t use a regex when you don’t need to 🙂 $valid = filter_var($string, FILTER_VALIDATE_IP); Though if you really do want a regex… $valid = preg_match(‘/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/’, $string); The regex however will only validate the format, the max for any octet is the max for an unsigned byte, or 255. This is why IPv6 is necessary – … Read more

Docker container doesn’t expose ports when –net=host is mentioned in the docker run command

I was confused by this answer. Apparently my docker image should be reachable on port 8080. But it wasn’t. Then I read https://docs.docker.com/network/host/ To quote The host networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server. That’s rather annoying as … Read more

Creating InetAddress object in Java

You should be able to use getByName or getByAddress. The host name can either be a machine name, such as “java.sun.com”, or a textual representation of its IP address InetAddress addr = InetAddress.getByName(“127.0.0.1”); The method that takes a byte array can be used like this: byte[] ipAddr = new byte[]{127, 0, 0, 1}; InetAddress addr … Read more

How to access FastAPI backend from a different machine/IP on the same local network?

Make sure that the host flag is set to 0.0.0.0, when running the server— 0.0.0.0 means all IPv4 addresses on the local machine. If a host has two IP addresses, e.g., 192.168.10.2 and 10.1.2.5, and the server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs. For example, … Read more

Get All IP Addresses on Machine

The DNS variants work across the network, but one DNS entry can have many IP addresses and one IP address can have many DNS entries. More importantly, an address needn’t be bound to a DNS entry at all. For the local machine try this: foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces()) { Console.WriteLine(“Name: ” + netInterface.Name); Console.WriteLine(“Description: … Read more

How to check if an IP address is from a particular network/netmask in Java?

Option 1: Use spring-security-web‘s IpAddressMatcher. Unlike Apache Commons Net, it supports both ipv4 and ipv6. import org.springframework.security.web.util.matcher.IpAddressMatcher; … private void checkIpMatch() { matches(“192.168.2.1”, “192.168.2.1”); // true matches(“192.168.2.1”, “192.168.2.0/32”); // false matches(“192.168.2.5”, “192.168.2.0/24”); // true matches(“92.168.2.1”, “fe80:0:0:0:0:0:c0a8:1/120”); // false matches(“fe80:0:0:0:0:0:c0a8:11”, “fe80:0:0:0:0:0:c0a8:1/120”); // true matches(“fe80:0:0:0:0:0:c0a8:11”, “fe80:0:0:0:0:0:c0a8:1/128”); // false matches(“fe80:0:0:0:0:0:c0a8:11”, “192.168.2.0/32”); // false } private boolean matches(String ip, … Read more

How can I get the public IP using python2.7?

Currently there are several options: ip.42.pl jsonip.com httpbin.org ipify.org Below are exact ways you can utilize each of the above. ip.42.pl from urllib2 import urlopen my_ip = urlopen(‘http://ip.42.pl/raw’).read() This is the first option I have found. It is very convenient for scripts, you don’t need JSON parsing here. jsonip.com from json import load from urllib2 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)