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


Java InetAddress.toString方法代码示例

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


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

示例1: valueOf

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Converts an InetAddress into an IP address.
 *
 * @param inetAddress the InetAddress value to use
 * @return an IP address
 * @throws IllegalArgumentException if the argument is invalid
 */
public static IpAddress valueOf(InetAddress inetAddress) {
    byte[] bytes = inetAddress.getAddress();
    if (inetAddress instanceof Inet4Address) {
        return new IpAddress(Version.INET, bytes);
    }
    if (inetAddress instanceof Inet6Address) {
        return new IpAddress(Version.INET6, bytes);
    }
    // Use the number of bytes as a hint
    if (bytes.length == INET_BYTE_LENGTH) {
        return new IpAddress(Version.INET, bytes);
    }
    if (bytes.length == INET6_BYTE_LENGTH) {
        return new IpAddress(Version.INET6, bytes);
    }
    final String msg = "Unrecognized IP version address string: " +
        inetAddress.toString();
    throw new IllegalArgumentException(msg);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:IpAddress.java

示例2: getAllUsedIpAddresses

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Get a list of all already used ip addresses with its subnetmask.
 * @returns ArrayList of all used ipaddresses.
 */
public static ArrayList<String> getAllUsedIpAddresses() {
    ArrayList<String> ipaddresses = new ArrayList<>();
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress tmpAddress = enumIpAddr.nextElement();
                short subnet = NetworkInterface.getByInetAddress(tmpAddress).getInterfaceAddresses().get(0).getNetworkPrefixLength();
                String ip = tmpAddress.toString() + "/" + subnet;
                // Only ipv4 addresses.
                if (ip.contains(".")) {
                    // remove prefix "/"
                    ipaddresses.add(ip.substring(1));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ipaddresses;
}
 
开发者ID:Hatzen,项目名称:EasyPeasyVPN,代码行数:26,代码来源:NetworkUtilities.java

示例3: 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

示例4: IPSubnet

import java.net.InetAddress; //导入方法依赖的package包/类
public IPSubnet(InetAddress addr, int mask) throws UnknownHostException
{
	_addr = addr.getAddress();
	_isIPv4 = _addr.length == 4;
	_mask = getMask(mask, _addr.length);
	if (!applyMask(_addr))
	{
		throw new UnknownHostException(addr.toString() + "/" + mask);
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:11,代码来源:IPSubnet.java

示例5: format

import java.net.InetAddress; //导入方法依赖的package包/类
@SuppressForbidden(reason = "we call toString to avoid a DNS lookup")
static String format(InetAddress address, int port, boolean includeHost) {
    Objects.requireNonNull(address);
    
    StringBuilder builder = new StringBuilder();

    if (includeHost) {
        // must use toString, to avoid DNS lookup. but the format is specified in the spec
        String toString = address.toString();
        int separator = toString.indexOf('/');
        if (separator > 0) {
            // append hostname, with the slash too
            builder.append(toString, 0, separator + 1);
        }
    }
            
    if (port != -1 && address instanceof Inet6Address) {
        builder.append(InetAddresses.toUriString(address));
    } else {
        builder.append(InetAddresses.toAddrString(address));
    }
    
    if (port != -1) {
        builder.append(':');
        builder.append(port);
    }
    
    return builder.toString();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:NetworkAddress.java

示例6: host

import java.net.InetAddress; //导入方法依赖的package包/类
/** @see #host(String...) */
public AuthorityClassifierBuilder host(InetAddress... addresses) {
  for (InetAddress address : addresses) {
    if (address instanceof Inet4Address) {
      ipv4s.add((Inet4Address) address);
    } else if (address instanceof Inet6Address) {
      ipv6s.add((Inet6Address) address);
    } else {
      throw new IllegalArgumentException(address.toString());
    }
  }
  return this;
}
 
开发者ID:OWASP,项目名称:url-classifier,代码行数:14,代码来源:AuthorityClassifierBuilder.java

示例7: JdpBroadcaster

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);

        if (interf == null) {
            throw new JdpException("Unable to get network interface for " + srcAddress.toString());
        }

        if (!interf.isUp()) {
            throw new JdpException(interf.getName() + " is not up.");
        }

        if (!interf.supportsMulticast()) {
            throw new JdpException(interf.getName() + " does not support multicast.");
        }

        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:JdpBroadcaster.java

示例8: serialize

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public String serialize(InetAddress data)
{
    String str = data.toString();
    int indexOf = str.indexOf('/');
    if (indexOf >= 0)
    {
        return str.substring(str.indexOf('/') + 1);
    }
    return str;
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:12,代码来源:InetAddressSerializer.java

示例9: toStringAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private String toStringAddress(InetAddress clientAddress, int clientPort) {
    return clientAddress.toString() + ":" + clientPort;
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:4,代码来源:CoapMessageTracer.java

示例10: getConnectedClients

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Returns modifiable map (changes do not effect this class) of client membershipID to connection
 * count. This is different from the map contained in this class as here the key is client
 * membershipID & not the the proxyID. It is to be noted that a given client can have multiple
 * proxies.
 * 
 * @param filterProxies Set identifying the Connection proxies which should be fetched. These
 *        ConnectionProxies may be from same client member or different. If it is null this would
 *        mean to fetch the Connections of all the ConnectionProxy objects.
 * 
 */
public Map getConnectedClients(Set filterProxies) {
  Map map = new HashMap(); // KEY=proxyID, VALUE=connectionCount (Integer)
  synchronized (_clientThreadsLock) {
    Iterator connectedClients = this._clientThreads.entrySet().iterator();
    while (connectedClients.hasNext()) {
      Map.Entry entry = (Map.Entry) connectedClients.next();
      ClientProxyMembershipID proxyID = (ClientProxyMembershipID) entry.getKey();// proxyID
                                                                                 // includes FQDN
      if (filterProxies == null || filterProxies.contains(proxyID)) {
        String membershipID = null;
        Set connections = (Set) entry.getValue();
        int socketPort = 0;
        InetAddress socketAddress = null;
        /// *
        Iterator serverConnections = connections.iterator();
        // Get data from one.
        while (serverConnections.hasNext()) {
          ServerConnection sc = (ServerConnection) serverConnections.next();
          socketPort = sc.getSocketPort();
          socketAddress = sc.getSocketAddress();
          membershipID = sc.getMembershipID();
          break;
        }
        // */
        int connectionCount = connections.size();
        String clientString = null;
        if (socketAddress == null) {
          clientString = "client member id=" + membershipID;
        } else {
          clientString = "host name=" + socketAddress.toString() + " host ip="
              + socketAddress.getHostAddress() + " client port=" + socketPort
              + " client member id=" + membershipID;
        }
        Object[] data = null;
        data = (Object[]) map.get(membershipID);
        if (data == null) {
          map.put(membershipID, new Object[] {clientString, Integer.valueOf(connectionCount)});
        } else {
          data[1] = Integer.valueOf(((Integer) data[1]).intValue() + connectionCount);
        }
        /*
         * Note: all client addresses are same... Iterator serverThreads = ((Set)
         * entry.getValue()).iterator(); while (serverThreads.hasNext()) { ServerConnection
         * connection = (ServerConnection) serverThreads.next(); InetAddress clientAddress =
         * connection.getClientAddress(); logger.severe("getConnectedClients: proxyID=" + proxyID
         * + " clientAddress=" + clientAddress + " FQDN=" + clientAddress.getCanonicalHostName());
         * }
         */
      }
    }

  }
  return map;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:66,代码来源:ClientHealthMonitor.java

示例11: sayHelloWithInetAddress

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public String sayHelloWithInetAddress(InetAddress ipAddr)
        throws RemoteException {
    String response = "Hello with InetAddress " + ipAddr.toString();
    return response;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:HelloImpl.java

示例12: before

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
@SuppressLint("SdCardPath")
protected void before(XParam param) throws Throwable {
	if (mMethod == Methods.connect) {
		if (param.args.length > 2 && param.args[1] instanceof InetAddress && param.args[2] instanceof Integer) {
			InetAddress address = (InetAddress) param.args[1];
			int port = (Integer) param.args[2];

			String hostName;
			int uid = Binder.getCallingUid();
			boolean resolve = PrivacyManager.getSettingBool(uid, PrivacyManager.cSettingResolve, false);
			boolean noresolve = PrivacyManager.getSettingBool(-uid, PrivacyManager.cSettingNoResolve, false);
			if (resolve && !noresolve)
				try {
					hostName = address.getHostName();
				} catch (Throwable ignored) {
					hostName = address.toString();
				}
			else
				hostName = address.toString();

			if (isRestrictedExtra(param, hostName + ":" + port))
				param.setThrowable(new SocketException("XPrivacy"));
		}

	} else if (mMethod == Methods.open) {
		if (param.args.length > 0) {
			String fileName = (String) param.args[0];
			if (mFileName == null && fileName != null) {
				// Get storage folders
				if (mExternalStorage == null) {
					mExternalStorage = System.getenv("EXTERNAL_STORAGE");
					mEmulatedSource = System.getenv("EMULATED_STORAGE_SOURCE");
					mEmulatedTarget = System.getenv("EMULATED_STORAGE_TARGET");
					mMediaStorage = System.getenv("MEDIA_STORAGE");
					mSecondaryStorage = System.getenv("SECONDARY_STORAGE");
					if (TextUtils.isEmpty(mMediaStorage))
						mMediaStorage = "/data/media";
				}

				// Check storage folders
				if (fileName.startsWith("/sdcard")
						|| (mExternalStorage != null && fileName.startsWith(mExternalStorage))
						|| (mEmulatedSource != null && fileName.startsWith(mEmulatedSource))
						|| (mEmulatedTarget != null && fileName.startsWith(mEmulatedTarget))
						|| (mMediaStorage != null && fileName.startsWith(mMediaStorage))
						|| (mSecondaryStorage != null && fileName.startsWith(mSecondaryStorage)))
					if (isRestrictedExtra(param, fileName))
						param.setThrowable(new FileNotFoundException("XPrivacy"));

			} else if (fileName.startsWith(mFileName) || mFileName.contains("...")) {
				// Zygote, Android
				if (Util.getAppId(Process.myUid()) == Process.SYSTEM_UID)
					return;

				// Proc white list
				if (mFileName.equals("/proc"))
					if ("/proc/self/cmdline".equals(fileName))
						return;

				// Check if restricted
				if (mFileName.contains("...")) {
					String[] component = mFileName.split("\\.\\.\\.");
					if (fileName.startsWith(component[0]) && fileName.endsWith(component[1]))
						if (isRestricted(param, mFileName))
							param.setThrowable(new FileNotFoundException("XPrivacy"));

				} else if (mFileName.equals("/proc")) {
					if (isRestrictedExtra(param, mFileName, fileName))
						param.setThrowable(new FileNotFoundException("XPrivacy"));

				} else {
					if (isRestricted(param, mFileName))
						param.setThrowable(new FileNotFoundException("XPrivacy"));
				}
			}
		}

	} else
		Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:82,代码来源:XIoBridge.java

示例13: getServerGreetingsName

import java.net.InetAddress; //导入方法依赖的package包/类
public String getServerGreetingsName() {
    InetAddress serverAddress = getServerAddress();

    if (serverAddress != null)

        return serverAddress.toString();
    else

        return System.getProperty("user.name");
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:11,代码来源:SmtpConnection.java


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