当前位置: 首页>>代码示例>>Java>>正文


Java InetAddress.isSiteLocalAddress方法代码示例

本文整理汇总了Java中java.net.InetAddress.isSiteLocalAddress方法的典型用法代码示例。如果您正苦于以下问题:Java InetAddress.isSiteLocalAddress方法的具体用法?Java InetAddress.isSiteLocalAddress怎么用?Java InetAddress.isSiteLocalAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.InetAddress的用法示例。


在下文中一共展示了InetAddress.isSiteLocalAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocalIpAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private String getLocalIpAddress() {
    String ipAddrrss = "";
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {
            Enumeration<InetAddress> enumInetAddress = enumNetworkInterfaces.nextElement().getInetAddresses();
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();
                if (inetAddress.isSiteLocalAddress()) {
                    ipAddrrss = ipAddrrss + inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return ipAddrrss;
}
 
开发者ID:kevalpatel2106,项目名称:remote-storage-android-things,代码行数:19,代码来源:FTPManager.java

示例2: getIpAddress

import java.net.InetAddress; //导入方法依赖的package包/类
@ReactMethod
public void getIpAddress(Callback successCallback, Callback errorCallback) {
    WritableArray ipList = Arguments.createArray();
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();
                if (inetAddress.isSiteLocalAddress()) {
                    ipList.pushString(inetAddress.getHostAddress());
                }
            }
        }
    } catch (SocketException e) {
        Log.e(eTag, "getIpAddress SocketException", e);
        errorCallback.invoke(e.getMessage());
    }
    successCallback.invoke(ipList);
}
 
开发者ID:davidstoneham,项目名称:react-native-sockets,代码行数:22,代码来源:SocketsModule.java

示例3: addPublicAddress

import java.net.InetAddress; //导入方法依赖的package包/类
protected void
addPublicAddress(
	Set<InetAddress>	addresses,
	InetAddress			address )
{
	if ( address == null ){

		return;
	}

	if ( 	address.isAnyLocalAddress() ||
			address.isLoopbackAddress() ||
			address.isLinkLocalAddress()||
			address.isSiteLocalAddress()){

			return;
	}

	addresses.add( address );
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:21,代码来源:NetStatusPluginTester.java

示例4: getPublicIP4

import java.net.InetAddress; //导入方法依赖的package包/类
static public String getPublicIP4() {

        Enumeration<NetworkInterface> ifs;
        try {
            ifs = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            e.printStackTrace();
            return null;
        }

        while (ifs.hasMoreElements()) {
            NetworkInterface iface = ifs.nextElement();
            Enumeration<InetAddress> iad = iface.getInetAddresses();
            while (iad.hasMoreElements()) {
                InetAddress localIP = iad.nextElement();
                if (!localIP.isSiteLocalAddress() && !localIP.isLoopbackAddress()) {
                    // found an IPv4 address
                    if (localIP instanceof java.net.Inet4Address)
                        return localIP.getHostAddress();
                }
            }
        }
        return null;
    }
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:25,代码来源:LocalHost.java

示例5: extractRemoteIp

import java.net.InetAddress; //导入方法依赖的package包/类
private String extractRemoteIp(HttpServletRequest request) {
    String forwardedHeader = request.getHeader("x-forwarded-for");

    if (forwardedHeader != null) {
        String[] addresses = forwardedHeader.split("[,]");

        for (String address : addresses) {
            try {
                InetAddress inetAddress = InetAddress.getByName(address);

                if (!inetAddress.isSiteLocalAddress()) {
                    return inetAddress.getHostAddress();
                }
            } catch (UnknownHostException e) {
                LOGGER.debug("Failed to resolve IP for address: {}", address);
            }
        }
    }

    return request.getRemoteAddr();
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:22,代码来源:MainResource.java

示例6: initIpAdresses

import java.net.InetAddress; //导入方法依赖的package包/类
private List<String> initIpAdresses() {
    List<String> result = new ArrayList<String>(2);
    String ip = initIpAddress();
    if (ip != null)
        result.add(ip);
    int intIpAddress = findDoubleNatIp();
    if (intIpAddress != 0) {
        byte[] bytes = BigInteger.valueOf(intIpAddress).toByteArray();
        InetAddress address = null;
        try {
            address = InetAddress.getByAddress(bytes);
        } catch (UnknownHostException ignored) {}
        if (address != null && address.isSiteLocalAddress())
            result.add(address.getHostAddress());
    }
    return result;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:18,代码来源:SambaDiscovery.java

示例7: getOurIpAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private String getOurIpAddress() {
    String ip = "";
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();
            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();

                if (inetAddress.isSiteLocalAddress()) {
                    return inetAddress.getHostAddress();
                }

            }

        }

    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        ip += "Something Wrong! " + e.toString() + "\n";
    }

    return ip;
}
 
开发者ID:BloomBooks,项目名称:BloomReader,代码行数:27,代码来源:NewBookListenerService.java

示例8: getSiteLocalAddresses

import java.net.InetAddress; //导入方法依赖的package包/类
/** Returns all site-local scope (private) addresses for interfaces that are up. */
static InetAddress[] getSiteLocalAddresses() throws SocketException {
    List<InetAddress> list = new ArrayList<>();
    for (NetworkInterface intf : getInterfaces()) {
        if (intf.isUp()) {
            for (InetAddress address : Collections.list(intf.getInetAddresses())) {
                if (address.isSiteLocalAddress()) {
                    list.add(address);
                }
            }
        }
    }
    if (list.isEmpty()) {
        throw new IllegalArgumentException("No up-and-running site-local (private) addresses found, got " + getInterfaces());
    }
    return list.toArray(new InetAddress[list.size()]);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:NetworkUtils.java

示例9: getGlobalAddresses

import java.net.InetAddress; //导入方法依赖的package包/类
/** Returns all global scope addresses for interfaces that are up. */
static InetAddress[] getGlobalAddresses() throws SocketException {
    List<InetAddress> list = new ArrayList<>();
    for (NetworkInterface intf : getInterfaces()) {
        if (intf.isUp()) {
            for (InetAddress address : Collections.list(intf.getInetAddresses())) {
                if (address.isLoopbackAddress() == false && 
                    address.isSiteLocalAddress() == false &&
                    address.isLinkLocalAddress() == false) {
                    list.add(address);
                }
            }
        }
    }
    if (list.isEmpty()) {
        throw new IllegalArgumentException("No up-and-running global-scope (public) addresses found, got " + getInterfaces());
    }
    return list.toArray(new InetAddress[list.size()]);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:NetworkUtils.java

示例10: getRealIp

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getRealIp() {
	String localip = null;// 本地IP,如果没有配置外网IP则返回它
	String netip = null;// 外网IP
	try {
		Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
		InetAddress ip = null;
		boolean finded = false;//是否找到外网IP
		while (netInterfaces.hasMoreElements() && !finded) {
			NetworkInterface ni = netInterfaces.nextElement();
			Enumeration<InetAddress> address = ni.getInetAddresses();
			while (address.hasMoreElements()) {
				ip = address.nextElement();
				if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress()
						&& !ip.getHostAddress().contains(":")) {// 外网IP
					netip = ip.getHostAddress();
					finded = true;
					break;
				} else if (ip.isSiteLocalAddress()
						&& !ip.isLoopbackAddress()
						&& !ip.getHostAddress().contains(":")) {// 内网IP
					localip = ip.getHostAddress();
				}
			}
		}

		if (netip != null && !"".equals(netip)) {
			return netip;
		} else {
			return localip;
		}
	} catch (SocketException e) {
		logger.error("获取本机Ip失败:异常信息:" + e.getMessage());
		throw new RuntimeException(e);
	}
}
 
开发者ID:yanghuijava,项目名称:elephant,代码行数:36,代码来源:IPHelper.java

示例11: onLogin

import java.net.InetAddress; //导入方法依赖的package包/类
@EventHandler
public void onLogin(PlayerLoginEvent event) throws UnknownHostException {
    String host = event.getHostname();
    String addrStr = host.substring(0, host.indexOf(':'));
    InetAddress addr = InetAddress.getByName(addrStr);
    if (!addr.isLoopbackAddress() && !addr.isSiteLocalAddress()) {
        MCLibrary.setAddress(host);
        event.getHandlers().unregister(this);
    }
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:11,代码来源:ServerHostnameGetter.java

示例12: formatAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/** format internet address: java's default doesn't include everything useful */
private static String formatAddress(InterfaceAddress interfaceAddress) throws IOException {
    StringBuilder sb = new StringBuilder();

    InetAddress address = interfaceAddress.getAddress();
    if (address instanceof Inet6Address) {
        sb.append("inet6 ");
        sb.append(NetworkAddress.format(address));
        sb.append(" prefixlen:");
        sb.append(interfaceAddress.getNetworkPrefixLength());
    } else {
        sb.append("inet ");
        sb.append(NetworkAddress.format(address));
        int netmask = 0xFFFFFFFF << (32 - interfaceAddress.getNetworkPrefixLength());
        sb.append(" netmask:" + NetworkAddress.format(InetAddress.getByAddress(new byte[] {
                (byte)(netmask >>> 24),
                (byte)(netmask >>> 16 & 0xFF),
                (byte)(netmask >>> 8 & 0xFF),
                (byte)(netmask & 0xFF)
        })));
        InetAddress broadcast = interfaceAddress.getBroadcast();
        if (broadcast != null) {
            sb.append(" broadcast:" + NetworkAddress.format(broadcast));
        }
    }
    if (address.isLoopbackAddress()) {
        sb.append(" scope:host");
    } else if (address.isLinkLocalAddress()) {
        sb.append(" scope:link");
    } else if (address.isSiteLocalAddress()) {
        sb.append(" scope:site");
    }
    return sb.toString();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:IfConfig.java

示例13: scrubInetAddress

import java.net.InetAddress; //导入方法依赖的package包/类
@Nullable
public static String scrubInetAddress(InetAddress address) {
	// don't scrub link and site local addresses
	if (address.isLinkLocalAddress() || address.isSiteLocalAddress())
		return address.toString();
	// completely scrub IPv6 addresses
	if (address instanceof Inet6Address) return "[scrubbed]";
	// keep first and last octet of IPv4 addresses
	return scrubInetAddress(address.toString());
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:11,代码来源:PrivacyUtils.java

示例14: IpType

import java.net.InetAddress; //导入方法依赖的package包/类
public static String IpType(InetAddress inetAddress)
{
    try
    {
        final String ipVersion;
        if (inetAddress instanceof Inet4Address)
            ipVersion = "ipv4";
        else if (inetAddress instanceof Inet6Address)
            ipVersion = "ipv6";
        else
            ipVersion = "ipv?";
        
        if (inetAddress.isAnyLocalAddress())
            return "wildcard_" + ipVersion;
        if (inetAddress.isSiteLocalAddress())
            return "site_local_" + ipVersion;
        if (inetAddress.isLinkLocalAddress())
            return "link_local_" + ipVersion;
        if (inetAddress.isLoopbackAddress())
            return "loopback_" + ipVersion;
        return "public_" + ipVersion;

    }
    catch (final IllegalArgumentException e)
    {
        return "illegal_ip";
    }
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:29,代码来源:Helperfunctions.java

示例15: formatAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/** format internet address: java's default doesn't include everything useful */
private static String formatAddress(InterfaceAddress interfaceAddress) throws IOException {
    StringBuilder sb = new StringBuilder();
    
    InetAddress address = interfaceAddress.getAddress();
    if (address instanceof Inet6Address) {
        sb.append("inet6 ");
        sb.append(NetworkAddress.formatAddress(address));
        sb.append(" prefixlen:");
        sb.append(interfaceAddress.getNetworkPrefixLength());
    } else {
        sb.append("inet ");
        sb.append(NetworkAddress.formatAddress(address));
        int netmask = 0xFFFFFFFF << (32 - interfaceAddress.getNetworkPrefixLength());
        sb.append(" netmask:" + NetworkAddress.formatAddress(InetAddress.getByAddress(new byte[] {
                (byte)(netmask >>> 24), 
                (byte)(netmask >>> 16 & 0xFF), 
                (byte)(netmask >>> 8 & 0xFF), 
                (byte)(netmask & 0xFF) 
        })));
        InetAddress broadcast = interfaceAddress.getBroadcast();
        if (broadcast != null) {
            sb.append(" broadcast:" + NetworkAddress.formatAddress(broadcast));
        }
    }
    if (address.isLoopbackAddress()) {
        sb.append(" scope:host");
    } else if (address.isLinkLocalAddress()) {
        sb.append(" scope:link");
    } else if (address.isSiteLocalAddress()) {
        sb.append(" scope:site");
    }
    return sb.toString();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:35,代码来源:IfConfig.java


注:本文中的java.net.InetAddress.isSiteLocalAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。