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


Java InetAddress.equals方法代码示例

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


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

示例1: checkConnectImpl

import java.net.InetAddress; //导入方法依赖的package包/类
final void checkConnectImpl(String host, int port) {
    Class insecure = getInsecureClass();
    if (insecure != null) {  
        URL ctx = getClassURL(insecure);
        if (ctx != null) {
            try {
                String fromHost = ctx.getHost();
                InetAddress ia2 = InetAddress.getByName(host);
                InetAddress ia3 = InetAddress.getByName(fromHost);
                if (ia2.equals(ia3)) {
                    return;
                }
            } catch (UnknownHostException e) { // ignore
                e.printStackTrace();
            }
        }
        throw new SecurityException();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:TopSecurityManager.java

示例2: throwExceptionIfForbidden

import java.net.InetAddress; //导入方法依赖的package包/类
public void throwExceptionIfForbidden(String host, int port) throws IOException {
    logDebugTrace("throwExceptionIfForbidden(host=" + host + " port=" + port + ") with " + "isSocketRestrictingOnlyLocalHost="
        + isSocketRestrictingOnlyLocalHost.get());
    Boolean flag = isSocketRestrictingOnlyLocalHost.get();
    if (flag != null && flag.booleanValue()) {
        InetAddress inetAddress;
        // Trying to resolve host to check if this resolves to loopback where is started
        InetAddress loopBack = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 });
        try {
            inetAddress = InetAddress.getByName(host);
        } catch (UnknownHostException e) {
            // Unable to resolve host, unlikely to be loopback
            inetAddress = null;
        }
        if (inetAddress == null || !inetAddress.equals(loopBack)) {
            IOException ioe = new IOException("detected direct socket connect while tests expect them to go "
                + "through proxy instead: Only jetty proxy threads should go through external hosts, got:host=" + host + " port="
                + port);
            printStackTrace(ioe);
            throw ioe;
        }
    }
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:24,代码来源:SocketDestHelper.java

示例3: sameAs

import java.net.InetAddress; //导入方法依赖的package包/类
protected boolean
sameAs(
	NetworkAdminNATDeviceImpl	other )
{
	if ( 	!getAddress().equals( other.getAddress()) ||
			getPort() != other.getPort()){

		return( false );
	}

	InetAddress e1 = getExternalAddress();
	InetAddress e2 = other.getExternalAddress();

	if ( e1 == null && e2 == null ){

		return( true );
	}
	if ( e1 == null || e2 == null ){

		return( false );
	}

	return( e1.equals( e2 ));
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:25,代码来源:NetworkAdminNATDeviceImpl.java

示例4: sameAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private boolean
sameAddress(
	InetAddress	a1,
	InetAddress a2 )
{
	if ( a1 == null && a2 == null ){

		return( true );

	}else if ( a1 == null || a2 == null ){

		return( false );

	}else{

		return( a1.equals( a2 ));
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:19,代码来源:WebPlugin.java

示例5: getDefaultNetworkInteface

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * this function, invoked by <code>getNetworkSpeed()</code>, identifies default network interface
 * @return The name of default network interface
 * @throws SocketException exception managed in <code>getNetworkSpeed()</code>
 * @throws UnknownHostException exception managed in <code>getNetworkSpeed()</code>
 */
private String getDefaultNetworkInteface() throws SocketException, UnknownHostException {
    Enumeration<NetworkInterface> netifs = NetworkInterface.getNetworkInterfaces();

    InetAddress myAddr = InetAddress.getLocalHost();

    while (netifs.hasMoreElements()) {
        NetworkInterface networkInterface = netifs.nextElement();
        Enumeration<InetAddress> inAddrs = networkInterface.getInetAddresses();
        while (inAddrs.hasMoreElements()) {
            InetAddress inAddr = inAddrs.nextElement();
            if (inAddr.equals(myAddr)) {
                return networkInterface.getName();
            }
        }
    }
    return "";
}
 
开发者ID:andrea9293,项目名称:pcstatus,代码行数:24,代码来源:NetworkStats.java

示例6: serviceChange

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public void serviceChange(UUID serverid, String service, JSONObject data, boolean up)
{
    if (!service.equals(Discovery.DATABASE_TYPE))
        return;
    InetAddress ip = (InetAddress)data.get("ip");
    if (ip.equals(Network.getPrimaryAddress()))
        return;
    System.out.println(ip + ", " + data + ", " + up);
    if (up) {
        Database.d.mergeServerActivate(serverid, (String)data.get("hostname"), ip.getHostAddress());
    } else {
        Database.d.mergeServerDeactivate(serverid);
    }
    Messenger.sendEvent(MT.POKE_SYNC_SERVER, true);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:17,代码来源:Monitors.java

示例7: isInternetAvailable

import java.net.InetAddress; //导入方法依赖的package包/类
public boolean isInternetAvailable() {
    try {
        InetAddress ipAddr = InetAddress.getByName("google.com"); //You can replace it with your name
        return !ipAddr.equals("");

    } catch (Exception e) {
        return false;
    }

}
 
开发者ID:someaditya,项目名称:CoinPryc,代码行数:11,代码来源:MainActivity.java

示例8: checkMembership

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Checks registry for membership of the group on the given
 * network interface.
 */
MembershipKey checkMembership(InetAddress group, NetworkInterface interf,
                              InetAddress source)
{
    if (groups != null) {
        List<MembershipKeyImpl> keys = groups.get(group);
        if (keys != null) {
            for (MembershipKeyImpl key: keys) {
                if (key.networkInterface().equals(interf)) {
                    // already a member to receive all packets so return
                    // existing key or detect conflict
                    if (source == null) {
                        if (key.sourceAddress() == null)
                            return key;
                        throw new IllegalStateException("Already a member to receive all packets");
                    }

                    // already have source-specific membership so return key
                    // or detect conflict
                    if (key.sourceAddress() == null)
                        throw new IllegalStateException("Already have source-specific membership");
                    if (source.equals(key.sourceAddress()))
                        return key;
                }
            }
        }
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:MembershipRegistry.java

示例9: setIpInfoFromNetworkInterface

import java.net.InetAddress; //导入方法依赖的package包/类
private void setIpInfoFromNetworkInterface() {
    try {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        if (networkInterfaces == null) {
            return;
        }
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface netIf = networkInterfaces.nextElement();

            for (Enumeration<InetAddress> inetAddresses = netIf.getInetAddresses(); inetAddresses.hasMoreElements();) {
                InetAddress inetAddress = inetAddresses.nextElement();
                if (inetAddress.isLoopbackAddress() || inetAddress instanceof Inet6Address) {
                    continue;
                }
                if (netIf.getDisplayName().contains("wlan0")
                        || netIf.getDisplayName().contains("eth0")
                        || netIf.getDisplayName().contains("ap0")) {
                    FDroidApp.ipAddressString = inetAddress.getHostAddress();
                    for (InterfaceAddress address : netIf.getInterfaceAddresses()) {
                        short networkPrefixLength = address.getNetworkPrefixLength();
                        if (networkPrefixLength > 32) {
                            // something is giving a "/64" netmask, IPv6?
                            // java.lang.IllegalArgumentException: Value [64] not in range [0,32]
                            continue;
                        }
                        if (inetAddress.equals(address.getAddress()) && !TextUtils.isEmpty(FDroidApp.ipAddressString)) {
                            String cidr = String.format(Locale.ENGLISH, "%s/%d",
                                    FDroidApp.ipAddressString, networkPrefixLength);
                            FDroidApp.subnetInfo = new SubnetUtils(cidr).getInfo();
                            break;
                        }
                    }
                }
            }
        }
    } catch (SocketException e) {
        Log.e(TAG, "Could not get ip address", e);
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:40,代码来源:WifiStateChangeService.java

示例10: Range

import java.net.InetAddress; //导入方法依赖的package包/类
Range(String key, String mask) {
    String[] splits = mask.split("/");
    if (splits.length != 2) {
        throw new IllegalArgumentException("Expected [ip/prefix_length] but got [" + mask
                + "], which contains zero or more than one [/]");
    }
    InetAddress value = InetAddresses.forString(splits[0]);
    int prefixLength = Integer.parseInt(splits[1]);
    // copied from InetAddressPoint.newPrefixQuery
    if (prefixLength < 0 || prefixLength > 8 * value.getAddress().length) {
        throw new IllegalArgumentException("illegal prefixLength [" + prefixLength
                + "] in [" + mask + "]. Must be 0-32 for IPv4 ranges, 0-128 for IPv6 ranges");
    }
    // create the lower value by zeroing out the host portion, upper value by filling it with all ones.
    byte lower[] = value.getAddress();
    byte upper[] = value.getAddress();
    for (int i = prefixLength; i < 8 * lower.length; i++) {
        int m = 1 << (7 - (i & 7));
        lower[i >> 3] &= ~m;
        upper[i >> 3] |= m;
    }
    this.key = key;
    try {
        InetAddress fromAddress = InetAddress.getByAddress(lower);
        if (fromAddress.equals(InetAddressPoint.MIN_VALUE)) {
            this.from = null;
        } else {
            this.from = InetAddresses.toAddrString(fromAddress);
        }
        InetAddress inclusiveToAddress = InetAddress.getByAddress(upper);
        if (inclusiveToAddress.equals(InetAddressPoint.MAX_VALUE)) {
            this.to = null;
        } else {
            this.to = InetAddresses.toAddrString(InetAddressPoint.nextUp(inclusiveToAddress));
        }
    } catch (UnknownHostException bogus) {
        throw new AssertionError(bogus);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:IpRangeAggregationBuilder.java

示例11: inetAddressConflict

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Checks if the test address and mask conflicts with the filter address and
 * mask
 *
 * For example:
 * testAddress: 172.28.2.23
 * testMask: 255.255.255.0
 * filterAddress: 172.28.1.10
 * testMask: 255.255.255.0
 * do conflict
 *
 * testAddress: 172.28.2.23
 * testMask: 255.255.255.0
 * filterAddress: 172.28.1.10
 * testMask: 255.255.0.0
 * do not conflict
 *
 * Null parameters are permitted
 *
 * @param testAddress
 * @param filterAddress
 * @param testMask
 * @param filterMask
 * @return
 */
public static boolean inetAddressConflict(final InetAddress testAddress, final InetAddress filterAddress, final InetAddress testMask,
        final InetAddress filterMask) {
    // Sanity check
    if (testAddress == null || filterAddress == null) {
        return false;
    }

    // Presence check
    if (isAny(testAddress) || isAny(filterAddress)) {
        return false;
    }

    int testMaskLen = testMask == null ? testAddress instanceof Inet4Address ? 32 : 128 : NetUtils
            .getSubnetMaskLength(testMask);
    int filterMaskLen = filterMask == null ? testAddress instanceof Inet4Address ? 32 : 128 : NetUtils
            .getSubnetMaskLength(filterMask);

    // Mask length check. Test mask has to be more specific than filter one
    if (testMaskLen < filterMaskLen) {
        return true;
    }

    // Subnet Prefix on filter mask length must be the same
    InetAddress prefix1 = getSubnetPrefix(testAddress, filterMaskLen);
    InetAddress prefix2 = getSubnetPrefix(filterAddress, filterMaskLen);
    return !prefix1.equals(prefix2);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:53,代码来源:NetUtils.java

示例12: getKnownAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private String getKnownAddress(String addr) {
    try {
        InetAddress a = InetAddress.getByName(addr);
        if (a.equals(dns1) || a.equals(dns2))
            return "dns";
        if (a.equals(vpn4) || a.equals(vpn6))
            return "vpn";
    } catch (UnknownHostException ignored) {
    }
    return addr;
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:12,代码来源:AdapterLog.java

示例13: getNatType

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getNatType(final InetAddress localAdr, final InetAddress publicAdr)
{
    try
    {
        final String ipVersionLocal;
        final String ipVersionPublic;
        if (publicAdr instanceof Inet4Address)
            ipVersionPublic = "ipv4";
        else if (publicAdr instanceof Inet6Address)
            ipVersionPublic = "ipv6";
        else
            ipVersionPublic = "ipv?";

        if (localAdr instanceof Inet4Address)
            ipVersionLocal = "ipv4";
        else if (localAdr instanceof Inet6Address)
            ipVersionLocal = "ipv6";
        else
            ipVersionLocal = "ipv?";
        
        if (localAdr.equals(publicAdr))
            return "no_nat_" + ipVersionPublic;
        else
        {
            final String localType = isIPLocal(localAdr) ? "local" : "public";
            final String publicType = isIPLocal(publicAdr) ? "local" : "public";
            if (ipVersionLocal.equals(ipVersionPublic)) {
                return String.format("nat_%s_to_%s_%s", localType, publicType, ipVersionPublic);
            } else {
                return String.format("nat_%s_to_%s_%s", ipVersionLocal, publicType, ipVersionPublic);
            }
        }
    }
    catch (final IllegalArgumentException e)
    {
        return "illegal_ip";
    }
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:39,代码来源:Helperfunctions.java

示例14: isInternetAvailable

import java.net.InetAddress; //导入方法依赖的package包/类
private boolean isInternetAvailable() {
    try {
        final InetAddress address = InetAddress.getByName("www.google.com");
        if(!address.equals("")){
            return true;
        }
        return !address.equals("");
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:fga-gpp-mds,项目名称:2017.1-Trezentos,代码行数:14,代码来源:ServerOperationEvaluationFragment.java

示例15: isInternetAvailable

import java.net.InetAddress; //导入方法依赖的package包/类
private boolean isInternetAvailable() {
    try {
        final InetAddress address = InetAddress.getByName("www.google.com");
        if(!address.equals("")){
            return true;
        }
        //return !address.equals("");
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:fga-gpp-mds,项目名称:2017.1-Trezentos,代码行数:14,代码来源:ServerOperationExamsActivity.java


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