隐藏掉IP地址的最后一部分为 * 代替

@param ip IP地址
@return 隐藏部分后的IP
495420
public static String hideIpPart(String ip) {
		return new StringBuffer(ip.length()).append(ip.substring(0, ip.lastIndexOf(".") + 1)).append("*").toString();
	}
1116816
public static String queryIp(String host) {
		InetAddress[] addresses;
		try {
			addresses = InetAddress.getAllByName(host);
		}
		catch (UnknownHostException e) {
			return null;
		}
		// System.out.println("len:" + addresses.length);
		if (addresses.length == 1) {
			return addresses[0].getHostAddress();
		}
		else {
			// 多IP时，随机返回一个
			int random = new Random().nextInt(addresses.length);
			return addresses[random].getHostAddress();
		}
	}
517820
public static InetAddress parse(final String ip)
	{
		if (ip == null || ip.isEmpty())
			throw new IllegalArgumentException("A null or empty string is not a valid IP address!");

		try
		{
			return InetAddress.getByName(ip);
		}
		catch (Throwable t)
		{
			throw new IllegalArgumentException("Not a valid IP address: " + ip, t);
		}
	}
88139
public DescribeIpResponse describeIp(String ip) {
        DescribeIpRequest request = new DescribeIpRequest()
                .withIp(ip);
        return describeIp(request);
    }
8111
public static synchronized boolean removeDenyIP(String ip) {
		if(deniedIP!=null && deniedIP.remove(ip)!=null) {
			writeIP();
			if(deniedIP.isEmpty()) {
				deniedIP=null;
			}
			return true;
		}
		return false;
	}
733271
@Override
  public <T> T instance(InjectionPoint<T> ip)
  {
    Objects.requireNonNull(ip);

    Provider<T> provider = provider(ip);

    if (provider != null) {
      return provider.get();
    }
    else {
      return null;
    }
  }
598239
public static synchronized boolean denyIP(String ip) {
		boolean rv = false;
		if(deniedIP==null) {
			deniedIP = new HashMap<String,Counter>();
			deniedIP.put(ip, new Counter(ip)); // Noted duplicated for minimum time spent
			rv= true;
		} else if(deniedIP.get(ip)==null) {
			deniedIP.put(ip, new Counter(ip));
			rv = true;
		}
		if(rv) {
			writeIP();
		}
		return rv;
	}
743577
protected function getLongIp($ip = null) : int
    {
        if ($ip === null) {
            $ip = $this->request->getClientIp();
        }

        return is_int($ip) ? $ip : ip2long($ip);
    }
1146928
public boolean inRange(InetAddress ip) throws FilterException {
        Iterator iter = ranges.iterator();
        while (iter.hasNext()) {
            IPAddressRange range = (IPAddressRange) iter.next();
            if (range.inRange(ip)) {
                return true;
            }
        }

        return false;
    }
936137
public static String getIP(final InetAddress inetAddress)
	{
		String ip = "";
		ip = inetAddress.getHostAddress();
		if (ip.equals(""))
		{
			final byte[] ipAddressInBytes = inetAddress.getAddress();
			for (int i = 0; i < ipAddressInBytes.length; i++)
			{
				if (i > 0)
				{
					ip += ".";
				}
				ip += ipAddressInBytes[i] & 0xFF;
			}
		}
		return ip;
	}
584847
public function getHostsForIp($ip)
    {
        // check binary representation of IP to avoid string case and short notation
        $ip = @inet_pton($ip);
        if ($ip === false) {
            return array();
        }

        $names = array();
        foreach (preg_split('/\r?\n/', $this->contents) as $line) {
            $parts = preg_split('/\s+/', $line, null, PREG_SPLIT_NO_EMPTY);
            $addr = array_shift($parts);

            // remove IPv6 zone ID (`fe80::1%lo0` => `fe80:1`)
            if (strpos($addr, ':') !== false && ($pos = strpos($addr, '%')) !== false) {
                $addr = substr($addr, 0, $pos);
            }

            if (@inet_pton($addr) === $ip) {
                foreach ($parts as $part) {
                    $names[] = $part;
                }
            }
        }

        return $names;
    }
569320
public static boolean isValidIp(final String ip) {
		if (ip == null || ip.length() == 0) {
			return false;
		}
		Matcher m = IS_VALID_IP_PATTERN.matcher(ip);
		return m.find();
		// return false;
		// }
		// return true;
	}
314276
public static function checkIp(string $ip, array $Ips = null): bool {
		// 内网ip列表
		$ruleIps = $Ips ?? [
				['10.0.0.0', '10.255.255.255'],
				['172.16.0.0', '172.31.255.255'],
				['192.168.0.0', '192.168.255.255'],
				['127.0.0.0', '127.255.255.255']
			];
		$ipInt   = ip2long(trim($ip));
		if ($ipInt === false)
			throw new InvalidArgumentException("Invalid IP[$ip].");
		foreach ($ruleIps as $rule) {
			if ($ipInt >= ip2long(reset($rule)) && $ipInt <= ip2long(end($rule))) {
				return true;
			}
		}
		return false;
	}
435487
public static InetAddress getAddress() {
    	
        try {
        	return InetAddress.getByAddress(new byte[] {0,0,0,0});
            /*for (Enumeration e = NetworkInterface.getNetworkInterfaces();
                    e.hasMoreElements();) {

                NetworkInterface ni = (NetworkInterface) e.nextElement();
                System.out.println("NetworkInterface = " + ni.getName());
                if (!ni.getName().contains("lo")) {
                    for (Enumeration ee = ni.getInetAddresses(); ee.hasMoreElements();) {
                        InetAddress ip = (InetAddress) ee.nextElement();
                        if (ip instanceof Inet4Address && ip.getAddress() != null) {
                            return ip;
                        }
                        //System.out.println("Ip's: " + ip.getHostAddress());
                    }
                }
            }
            NetworkInterface lo = NetworkInterface.getByName("lo");
            if (lo != null) {
                for (Enumeration ee = lo.getInetAddresses(); ee.hasMoreElements();) {
                    InetAddress ip = (InetAddress) ee.nextElement();
                    if (ip instanceof Inet4Address && ip.getAddress() != null) {
                        return ip;
                    }
                }
            }
            
            NetworkInterface lo0 = NetworkInterface.getByName("lo0");
            if (lo0 != null) {
                for (Enumeration ee = lo0.getInetAddresses(); ee.hasMoreElements();) {
                    InetAddress ip = (InetAddress) ee.nextElement();
                    if (ip instanceof Inet4Address && ip.getAddress() != null) {
                        return ip;
                    }
                }
            }*/
        } catch (Exception e) {
            System.err.println("Error");
        }
        return null;
    }
287412
def get_ip_list_by_multi_process_ping(ip_list=[], n=0, _type='stock'):
    ''' 
    '''
    cache = QA_util_cache()
    results = cache.get(_type)
    if results:
        # read the data from cache
        print('loading ip list from {} cache.'.format(_type))
    else:
        ips = [(x['ip'], x['port'], _type) for x in ip_list]
        ps = Parallelism()
        ps.add(ping, ips)
        ps.run()
        data = list(ps.get_results())
        results = []
        for i in range(len(data)):
            # 删除ping不通的数据
            if data[i] < datetime.timedelta(0, 9, 0):
                results.append((data[i], ip_list[i]))
        # 按照ping值从小大大排序
        results = [x[1] for x in sorted(results, key=lambda x: x[0])]
        if _type:
                # store the data as binary data stream
                cache.set(_type, results, age=86400)
                print('saving ip list to {} cache {}.'.format(_type, len(results)))
    if len(results) > 0:
        if n == 0 and len(results) > 0:
            return results
        else:
            return results[:n]
    else:
        print('ALL IP PING TIMEOUT!')
        return [{'ip': None, 'port': None}]
555871
public static boolean isValidIp(String ip) {
        if (!IP_PATTERN_FULL.matcher(ip).matches()) {
            return false;
        }
        String[] ipArr = ip.split("\\.");
        for (String part : ipArr) {
            int v = Integer.parseInt(part);
            if (v < 0 || v > 255) {
                return false;
            }
        }
        return true;
    }
771648
public static boolean isIPv4(final String ip) {
        if (StringUtils.isBlank(ip)) {
            return false;
        }

        final String regex = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
        final Pattern pattern = Pattern.compile(regex);
        final Matcher matcher = pattern.matcher(ip);

        return matcher.matches();
    }