List of usage examples for java.net InetAddress isAnyLocalAddress
public boolean isAnyLocalAddress()
From source file:com.netflix.spinnaker.halyard.deploy.provider.v1.kubernetes.KubernetesOperationFactory.java
private KubernetesLoadBalancerDescription baseLoadBalancerDescription(String accountName, SpinnakerService service) {/*from w w w.ja v a2 s .c om*/ String address = service.getAddress(); int port = service.getPort(); KubernetesLoadBalancerDescription description = new KubernetesLoadBalancerDescription(); String namespace = KubernetesProviderInterface.getNamespaceFromAddress(address); String name = KubernetesProviderInterface.getServiceFromAddress(address); Names parsedName = Names.parseName(name); description.setApp(parsedName.getApp()); description.setStack(parsedName.getStack()); description.setDetail(parsedName.getDetail()); description.setName(name); description.setNamespace(namespace); description.setAccount(accountName); KubernetesNamedServicePort servicePort = new KubernetesNamedServicePort(); servicePort.setPort(port); servicePort.setTargetPort(port); servicePort.setName("http"); servicePort.setProtocol("TCP"); if (service instanceof SpinnakerPublicService) { SpinnakerPublicService publicService = (SpinnakerPublicService) service; String publicAddress = publicService.getPublicAddress(); InetAddress addr; try { addr = InetAddress.getByName(publicAddress); } catch (UnknownHostException e) { throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to parse supplied public address: " + e.getMessage()).build()); } if (!(addr.isAnyLocalAddress() || addr.isLoopbackAddress())) { description.setLoadBalancerIp(publicService.getPublicAddress()); description.setServiceType("LoadBalancer"); } } List<KubernetesNamedServicePort> servicePorts = new ArrayList<>(); servicePorts.add(servicePort); description.setPorts(servicePorts); return description; }
From source file:de.sjka.logstash.osgi.internal.LogstashSender.java
@SuppressWarnings("unchecked") private void addIps(JSONObject values) { List<String> ip4s = new ArrayList<>(); List<String> ip6s = new ArrayList<>(); String ip = "unknown"; try {//from w w w .j a v a 2 s . co m Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaces.nextElement(); Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress address = inetAddresses.nextElement(); if (address instanceof Inet4Address) { ip4s.add(address.getHostAddress() + "_" + address.getHostName()); if (!address.isLinkLocalAddress() && !address.isAnyLocalAddress() && !address.isLoopbackAddress()) { ip = address.getHostAddress(); } } if (address instanceof Inet6Address) { ip6s.add(address.getHostAddress() + "_" + address.getHostName()); } } } ip4s.add("LOC_" + InetAddress.getLocalHost().getHostAddress() + "_" + InetAddress.getLocalHost().getHostName()); if (!ip4s.isEmpty()) { values.put("ip", ip); values.put("ip4s", ip4s); } if (!ip6s.isEmpty()) { values.put("ip6s", ip6s); } } catch (UnknownHostException | SocketException e) { values.put("ip", "offline_" + e.getMessage()); } }
From source file:com.ethlo.geodata.GeodataServiceImpl.java
@Override public GeoLocation findByIp(String ip) { if (!InetAddresses.isInetAddress(ip)) { return null; }/*from w w w . j a v a 2 s . c o m*/ final InetAddress address = InetAddresses.forString(ip); final boolean isLocalAddress = address.isLoopbackAddress() || address.isAnyLocalAddress(); if (isLocalAddress) { return null; } final long ipLong = UnsignedInteger.fromIntBits(InetAddresses.coerceToInteger(InetAddresses.forString(ip))) .longValue(); final Long id = ipRanges.get(ipLong); return id != null ? findById(id) : null; }
From source file:com.photon.phresco.framework.rest.api.UtilService.java
private boolean isRequestFromLocalMachine(InetAddress addr) { // Check if the address is a valid special local or loop back if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true; // Check if the address is defined on any interface try {// www . ja va 2 s . c o m return NetworkInterface.getByInetAddress(addr) != null; } catch (SocketException e) { return false; } }
From source file:com.turt2live.xmail.mail.Mail.java
/** * Determines if this mail is from this server. This only verifies if the mail is from a Minecraft server (this one specifically). * If the mail is from a website, desktop application, or otherwise not a Minecraft server then this will return true as * * @return true if this mail is to be considered from this server, false otherwise *//*from w w w. j a v a2 s . co m*/ public boolean fromThisServer() { String ip = getServerSender(); if (ip == null) { return true; } try { InetAddress add = InetAddress.getByName(ip); if (add.isAnyLocalAddress() || add.isLoopbackAddress()) { return true; } } catch (UnknownHostException e) { e.printStackTrace(); } return XMailConfig.getIP().equalsIgnoreCase(ip); }
From source file:org.parosproxy.paros.core.proxy.ProxyThread.java
private boolean isRecursive(HttpRequestHeader header) { try {//from w ww. ja v a 2s . c o m if (header.getHostPort() == inSocket.getLocalPort()) { String targetDomain = header.getHostName(); if (API.API_DOMAIN.equals(targetDomain)) { return true; } InetAddress targetAddress = InetAddress.getByName(targetDomain); if (parentServer.getProxyParam().isProxyIpAnyLocalAddress()) { if (targetAddress.isLoopbackAddress() || targetAddress.isSiteLocalAddress() || targetAddress.isAnyLocalAddress()) { return true; } } else if (targetAddress.equals(inSocket.getLocalAddress())) { return true; } } } catch (Exception e) { // ZAP: Log exceptions log.warn(e.getMessage(), e); } return false; }
From source file:com.vuze.plugin.azVPN_PIA.Checker.java
private int handleBound(InetAddress bindIP, StringBuilder sReply) { int newStatusID = STATUS_ID_OK; String s;//w ww . ja va 2 s. c o m boolean isGoodExistingBind = matchesVPNIP(bindIP); if (isGoodExistingBind) { String niName = "Unknown Interface"; try { NetworkInterface networkInterface = NetworkInterface.getByInetAddress(bindIP); niName = networkInterface.getName() + " (" + networkInterface.getDisplayName() + ")"; } catch (Throwable e) { } addReply(sReply, CHAR_GOOD, "pia.bound.good", new String[] { "" + bindIP, niName }); vpnIP = bindIP; } else { addReply(sReply, CHAR_BAD, "pia.bound.bad", new String[] { "" + bindIP }); newStatusID = STATUS_ID_BAD; } try { // Check if default routing goes through 10.*, by connecting to address // via socket. Address doesn't need to be reachable, just routable. // This works on Windows (in some cases), but on Mac returns a wildcard // address DatagramSocket socket = new DatagramSocket(); socket.connect(testSocketAddress, 0); InetAddress localAddress = socket.getLocalAddress(); socket.close(); if (!localAddress.isAnyLocalAddress()) { NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localAddress); s = texts.getLocalisedMessageText("pia.nonvuze.probable.route", new String[] { "" + localAddress, networkInterface.getName() + " (" + networkInterface.getDisplayName() + ")" }); char replyChar = ' '; if ((localAddress instanceof Inet4Address) && matchesVPNIP(localAddress)) { if (localAddress.equals(bindIP)) { replyChar = isGoodExistingBind ? CHAR_GOOD : CHAR_WARN; s += " " + texts.getLocalisedMessageText("pia.same.as.vuze"); } else { // Vuze is bound, default routing goes somewhere else // This is ok, since Vuze will not accept incoming from "somewhere else" // We'll warn, but not update the status id replyChar = CHAR_WARN; s += " " + texts.getLocalisedMessageText("pia.not.same"); if (isGoodExistingBind) { s += " " + texts.getLocalisedMessageText("default.routing.not.vpn.network.splitting"); } } addLiteralReply(sReply, replyChar + " " + s); if (!isGoodExistingBind && rebindNetworkInterface) { rebindNetworkInterface(networkInterface, localAddress, sReply); // Should we redo test? } } else { // Vuze is bound, default routing goes to somewhere else. // Probably network splitting replyChar = isGoodExistingBind ? CHAR_WARN : CHAR_BAD; if (isGoodExistingBind) { s += " " + texts.getLocalisedMessageText("default.routing.not.vpn.network.splitting"); } addLiteralReply(sReply, replyChar + " " + s); } } } catch (Throwable t) { t.printStackTrace(); } return newStatusID; }
From source file:com.vuze.plugin.azVPN_PIA.Checker.java
private int findBindingAddress(File pathPIAManagerData, StringBuilder sReply) { int newStatusID = -1; // Find our VPN binding (interface) address. Checking UDP is the best bet, // since TCP and http might be proxied List<PRUDPPacketHandler> handlers = PRUDPPacketHandlerFactory.getHandlers(); if (handlers.size() == 0) { PRUDPReleasablePacketHandler releasableHandler = PRUDPPacketHandlerFactory.getReleasableHandler(0); handlers = PRUDPPacketHandlerFactory.getHandlers(); releasableHandler.release();//w ww . ja va 2s . c o m } if (handlers.size() == 0) { addLiteralReply(sReply, CHAR_BAD + " No UDP Handlers"); newStatusID = STATUS_ID_BAD; } else { InetAddress bindIP = handlers.get(0).getBindIP(); // The "Any" field is equivalent to 0.0.0.0 in dotted-quad notation, which is unbound. // "Loopback" is 127.0.0.1, which is bound when Vuze can't bind to // user specified interface (ie. kill switched) if (bindIP.isAnyLocalAddress() || bindIP.isLoopbackAddress()) { newStatusID = handleUnboundOrLoopback(bindIP, sReply); if (newStatusID == STATUS_ID_BAD) { return newStatusID; } } else { newStatusID = handleBound(bindIP, sReply); } } return newStatusID; }
From source file:com.vuze.plugin.azVPN_PIA.Checker.java
private int handleUnboundOrLoopback(InetAddress bindIP, StringBuilder sReply) { int newStatusID = STATUS_ID_OK; InetAddress newBindIP = null; NetworkInterface newBindNetworkInterface = null; String s;/* w w w . j a v a2 s .c o m*/ if (bindIP.isAnyLocalAddress()) { addReply(sReply, CHAR_WARN, "pia.vuze.unbound"); } else { addReply(sReply, CHAR_BAD, "pia.vuze.loopback"); } try { NetworkAdmin networkAdmin = NetworkAdmin.getSingleton(); // Find a bindable address that starts with 10. InetAddress[] bindableAddresses = networkAdmin.getBindableAddresses(); for (InetAddress bindableAddress : bindableAddresses) { if (matchesVPNIP(bindableAddress)) { newBindIP = bindableAddress; newBindNetworkInterface = NetworkInterface.getByInetAddress(newBindIP); addReply(sReply, CHAR_GOOD, "pia.found.bindable.vpn", new String[] { "" + newBindIP }); break; } } // Find a Network Interface that has an address that starts with 10. NetworkAdminNetworkInterface[] interfaces = networkAdmin.getInterfaces(); boolean foundNIF = false; for (NetworkAdminNetworkInterface networkAdminInterface : interfaces) { NetworkAdminNetworkInterfaceAddress[] addresses = networkAdminInterface.getAddresses(); for (NetworkAdminNetworkInterfaceAddress a : addresses) { InetAddress address = a.getAddress(); if (address instanceof Inet4Address) { if (matchesVPNIP(address)) { s = texts.getLocalisedMessageText("pia.possible.vpn", new String[] { "" + address, networkAdminInterface.getName() + " (" + networkAdminInterface.getDisplayName() + ")" }); if (newBindIP == null) { foundNIF = true; newBindIP = address; // Either one should work //newBindNetworkInterface = NetworkInterface.getByInetAddress(newBindIP); newBindNetworkInterface = NetworkInterface .getByName(networkAdminInterface.getName()); s = CHAR_GOOD + " " + s + ". " + texts.getLocalisedMessageText("pia.assuming.vpn"); } else if (address.equals(newBindIP)) { s = CHAR_GOOD + " " + s + ". " + texts.getLocalisedMessageText("pia.same.address"); foundNIF = true; } else { if (newStatusID != STATUS_ID_BAD) { newStatusID = STATUS_ID_WARN; } s = CHAR_WARN + " " + s + ". " + texts.getLocalisedMessageText("pia.not.same.address"); } addLiteralReply(sReply, s); if (rebindNetworkInterface) { // stops message below from being added, we'll rebind later foundNIF = true; } } } } } if (!foundNIF) { addReply(sReply, CHAR_BAD, "pia.interface.not.found"); } // Check if default routing goes through 10.*, by connecting to address // via socket. Address doesn't need to be reachable, just routable. // This works on Windows, but on Mac returns a wildcard address DatagramSocket socket = new DatagramSocket(); socket.connect(testSocketAddress, 0); InetAddress localAddress = socket.getLocalAddress(); socket.close(); if (!localAddress.isAnyLocalAddress()) { NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localAddress); s = texts.getLocalisedMessageText("pia.nonvuze.probable.route", new String[] { "" + localAddress, networkInterface == null ? "null" : networkInterface.getName() + " (" + networkInterface.getDisplayName() + ")" }); if ((localAddress instanceof Inet4Address) && matchesVPNIP(localAddress)) { if (newBindIP == null) { newBindIP = localAddress; newBindNetworkInterface = networkInterface; s = CHAR_GOOD + " " + s + " " + texts.getLocalisedMessageText("pia.assuming.vpn"); } else if (localAddress.equals(newBindIP)) { s = CHAR_GOOD + " " + s + " " + texts.getLocalisedMessageText("pia.same.address"); } else { // Vuze not bound. We already found a boundable address, but it's not this one /* Possibly good case: * - Vuze: unbound * - Found Bindable: 10.100.1.6 * - Default Routing: 10.255.1.1 * -> Split network */ if (newStatusID != STATUS_ID_BAD) { newStatusID = STATUS_ID_WARN; } s = CHAR_WARN + " " + s + " " + texts.getLocalisedMessageText("pia.not.same.future.address") + " " + texts.getLocalisedMessageText("default.routing.not.vpn.network.splitting") + " " + texts.getLocalisedMessageText( "default.routing.not.vpn.network.splitting.unbound"); } addLiteralReply(sReply, s); } else { s = CHAR_WARN + " " + s; if (!bindIP.isLoopbackAddress()) { s += " " + texts.getLocalisedMessageText("default.routing.not.vpn.network.splitting"); } if (newBindIP == null && foundNIF) { if (newStatusID != STATUS_ID_BAD) { newStatusID = STATUS_ID_WARN; } s += " " + texts .getLocalisedMessageText("default.routing.not.vpn.network.splitting.unbound"); } addLiteralReply(sReply, s); } } } catch (Exception e) { e.printStackTrace(); addReply(sReply, CHAR_BAD, "pia.nat.error", new String[] { e.toString() }); } if (newBindIP == null) { addReply(sReply, CHAR_BAD, "pia.vpn.ip.detect.fail"); return STATUS_ID_BAD; } rebindNetworkInterface(newBindNetworkInterface, newBindIP, sReply); return newStatusID; }
From source file:com.vuze.plugin.azVPN_Air.Checker.java
private int handleBound(InetAddress bindIP, StringBuilder sReply) { int newStatusID = STATUS_ID_OK; String s;/*from w w w .j av a 2s . c o m*/ boolean isGoodExistingBind = matchesVPNIP(bindIP); if (isGoodExistingBind) { String niName = "Unknown Interface"; try { NetworkInterface networkInterface = NetworkInterface.getByInetAddress(bindIP); niName = networkInterface.getName() + " (" + networkInterface.getDisplayName() + ")"; } catch (Throwable e) { } addReply(sReply, CHAR_GOOD, "airvpn.bound.good", new String[] { "" + bindIP, niName }); vpnIP = bindIP; } else { addReply(sReply, CHAR_BAD, "airvpn.bound.bad", new String[] { "" + bindIP }); newStatusID = STATUS_ID_BAD; } try { // Check if default routing goes through 10.*, by connecting to address // via socket. Address doesn't need to be reachable, just routable. // This works on Windows (in some cases), but on Mac returns a wildcard // address DatagramSocket socket = new DatagramSocket(); socket.connect(testSocketAddress, 0); InetAddress localAddress = socket.getLocalAddress(); socket.close(); if (!localAddress.isAnyLocalAddress()) { NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localAddress); s = texts.getLocalisedMessageText("airvpn.nonvuze.probable.route", new String[] { "" + localAddress, networkInterface.getName() + " (" + networkInterface.getDisplayName() + ")" }); char replyChar = ' '; if ((localAddress instanceof Inet4Address) && matchesVPNIP(localAddress)) { if (localAddress.equals(bindIP)) { replyChar = isGoodExistingBind ? CHAR_GOOD : CHAR_WARN; s += " " + texts.getLocalisedMessageText("airvpn.same.as.vuze"); } else { // Vuze is bound, default routing goes somewhere else // This is ok, since Vuze will not accept incoming from "somewhere else" // We'll warn, but not update the status id replyChar = CHAR_WARN; s += " " + texts.getLocalisedMessageText("airvpn.not.same"); if (isGoodExistingBind) { s += " " + texts.getLocalisedMessageText("default.routing.not.vpn.network.splitting"); } } addLiteralReply(sReply, replyChar + " " + s); if (!isGoodExistingBind && rebindNetworkInterface) { rebindNetworkInterface(networkInterface, localAddress, sReply); // Should we redo test? } } else { // Vuze is bound, default routing goes to somewhere else. // Probably network splitting replyChar = isGoodExistingBind ? CHAR_WARN : CHAR_BAD; if (isGoodExistingBind) { s += " " + texts.getLocalisedMessageText("default.routing.not.vpn.network.splitting"); } addLiteralReply(sReply, replyChar + " " + s); } } } catch (Throwable t) { t.printStackTrace(); } return newStatusID; }