當前位置: 首頁>>代碼示例>>Java>>正文


Java Inet6Address類代碼示例

本文整理匯總了Java中java.net.Inet6Address的典型用法代碼示例。如果您正苦於以下問題:Java Inet6Address類的具體用法?Java Inet6Address怎麽用?Java Inet6Address使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Inet6Address類屬於java.net包,在下文中一共展示了Inet6Address類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.net.Inet6Address; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    // args[0] == generate-loopback generates serial data for loopback if
    // args[0] == generateAll generates serial data for interfaces with an
    // IPV6 address binding

    if (args.length != 0) {

        if (args[0].equals("generate-loopback")) {

            generateSerializedInet6AddressData(Inet6Address.getByAddress(
                    InetAddress.getLoopbackAddress().getHostName(),
                    LOOPBACKIPV6ADDRESS, LOOPBACK_SCOPE_ID), System.out,
                    true);

        } else {
            generateAllInet6AddressSerializedData();
        }
    } else {
        runTests();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:Inet6AddressSerializationTest.java

示例2: onClickConnect

import java.net.Inet6Address; //導入依賴的package包/類
/**
     * When the user clicks the button to submit the ip address
     * this activity is finished and the ip is passed on as data to the previous activity.
     * @param view
     */
    public void onClickConnect(View view) {
        bootstrapView = (EditText) findViewById(R.id.bootstrap_IP);
        try{
            Object res = InetAddress.getByName(bootstrapView.getText().toString());
            if(!(res instanceof Inet4Address) && !(res instanceof Inet6Address)){
                Log.i("Bootstrap IP Adress: ", res.toString());
                throw new Exception("Bootstrap IP is not a valid IP4 or IP6 address.");
            }
            Intent returnIntent = new Intent();
            BootstrapIPStorage.setIP(this, bootstrapView.getText().toString());
            returnIntent.putExtra("ConnectableAddress",bootstrapView.getText().toString());
            setResult(OverviewConnectionsActivity.RESULT_OK,returnIntent);
            finish();
        } catch (Exception e){
            Toast.makeText(this, "The bootstrap IP address is not a valid IP address: " + bootstrapView.getText().toString(), Toast.LENGTH_SHORT).show();
//             e.printStackTrace();
        }
    }
 
開發者ID:wkmeijer,項目名稱:CS4160-trustchain-android,代碼行數:24,代碼來源:BootstrapActivity.java

示例3: getThisHostIPV6Address

import java.net.Inet6Address; //導入依賴的package包/類
private static byte[] getThisHostIPV6Address(String hostName)
        throws Exception {
    InetAddress[] thisHostIPAddresses = null;
    try {
        thisHostIPAddresses = InetAddress.getAllByName(InetAddress
                .getLocalHost().getHostName());
    } catch (UnknownHostException uhEx) {
        uhEx.printStackTrace();
        throw uhEx;
    }
    byte[] thisHostIPV6Address = null;
    for (InetAddress inetAddress : thisHostIPAddresses) {
        if (inetAddress instanceof Inet6Address) {
            if (inetAddress.getHostName().equals(hostName)) {
                thisHostIPV6Address = inetAddress.getAddress();
                break;
            }
        }
    }
    // System.err.println("getThisHostIPV6Address: address is "
    // + Arrays.toString(thisHostIPV6Address));
    return thisHostIPV6Address;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:Inet6AddressSerializationTest.java

示例4: ConnectionBean

import java.net.Inet6Address; //導入依賴的package包/類
public ConnectionBean(ServerCnxn connection,ZooKeeperServer zk){
    this.connection = connection;
    this.stats = connection;
    this.zk = zk;
    
    InetSocketAddress sockAddr = connection.getRemoteSocketAddress();
    if (sockAddr == null) {
        remoteIP = "Unknown";
    } else {
        InetAddress addr = sockAddr.getAddress();
        if (addr instanceof Inet6Address) {
            remoteIP = ObjectName.quote(addr.getHostAddress());
        } else {
            remoteIP = addr.getHostAddress();
        }
    }
    sessionId = connection.getSessionId();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:19,代碼來源:ConnectionBean.java

示例5: toAddrString

import java.net.Inet6Address; //導入依賴的package包/類
/**
 * Returns the string representation of an {@link InetAddress}.
 *
 * <p>For IPv4 addresses, this is identical to {@link InetAddress#getHostAddress()}, but for IPv6
 * addresses, the output follows <a href="http://tools.ietf.org/html/rfc5952">RFC 5952</a> section
 * 4. The main difference is that this method uses "::" for zero compression, while Java's version
 * uses the uncompressed form.
 *
 * <p>This method uses hexadecimal for all IPv6 addresses, including IPv4-mapped IPv6 addresses
 * such as "::c000:201". The output does not include a Scope ID.
 *
 * @param ip {@link InetAddress} to be converted to an address string
 * @return {@code String} containing the text-formatted IP address
 * @since 10.0
 */
public static String toAddrString(InetAddress ip) {
  checkNotNull(ip);
  if (ip instanceof Inet4Address) {
    // For IPv4, Java's formatting is good enough.
    return ip.getHostAddress();
  }
  checkArgument(ip instanceof Inet6Address);
  byte[] bytes = ip.getAddress();
  int[] hextets = new int[IPV6_PART_COUNT];
  for (int i = 0; i < hextets.length; i++) {
    hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
  }
  compressLongestRunOfZeroes(hextets);
  return hextetsToIPv6String(hextets);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:31,代碼來源:InetAddresses.java

示例6: getTeredoInfo

import java.net.Inet6Address; //導入依賴的package包/類
/**
 * Returns the Teredo information embedded in a Teredo address.
 *
 * @param ip {@link Inet6Address} to be examined for embedded Teredo information
 * @return extracted {@code TeredoInfo}
 * @throws IllegalArgumentException if the argument is not a valid IPv6 Teredo address
 */
public static TeredoInfo getTeredoInfo(Inet6Address ip) {
  checkArgument(isTeredoAddress(ip), "Address '%s' is not a Teredo address.", toAddrString(ip));

  byte[] bytes = ip.getAddress();
  Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8));

  int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff;

  // Teredo obfuscates the mapped client port, per section 4 of the RFC.
  int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff;

  byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16);
  for (int i = 0; i < clientBytes.length; i++) {
    // Teredo obfuscates the mapped client IP, per section 4 of the RFC.
    clientBytes[i] = (byte) ~clientBytes[i];
  }
  Inet4Address client = getInet4Address(clientBytes);

  return new TeredoInfo(server, client, port, flags);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:28,代碼來源:InetAddresses.java

示例7: isIsatapAddress

import java.net.Inet6Address; //導入依賴的package包/類
/**
 * Evaluates whether the argument is an ISATAP address.
 *
 * <p>From RFC 5214: "ISATAP interface identifiers are constructed in Modified EUI-64 format [...]
 * by concatenating the 24-bit IANA OUI (00-00-5E), the 8-bit hexadecimal value 0xFE, and a 32-bit
 * IPv4 address in network byte order [...]"
 *
 * <p>For more on ISATAP addresses see section 6.1 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc5214#section-6.1">RFC 5214</a>.
 *
 * @param ip {@link Inet6Address} to be examined for ISATAP address format
 * @return {@code true} if the argument is an ISATAP address
 */
public static boolean isIsatapAddress(Inet6Address ip) {

  // If it's a Teredo address with the right port (41217, or 0xa101)
  // which would be encoded as 0x5efe then it can't be an ISATAP address.
  if (isTeredoAddress(ip)) {
    return false;
  }

  byte[] bytes = ip.getAddress();

  if ((bytes[8] | (byte) 0x03) != (byte) 0x03) {

    // Verify that high byte of the 64 bit identifier is zero, modulo
    // the U/L and G bits, with which we are not concerned.
    return false;
  }

  return (bytes[9] == (byte) 0x00) && (bytes[10] == (byte) 0x5e) && (bytes[11] == (byte) 0xfe);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:33,代碼來源:InetAddresses.java

示例8: getActiveNetworkInterfaceIP

import java.net.Inet6Address; //導入依賴的package包/類
private String getActiveNetworkInterfaceIP() throws SocketException {
    Enumeration<NetworkInterface>
            networkInterface = NetworkInterface.getNetworkInterfaces();
    String ipv6AddrStr = null;
    while (networkInterface.hasMoreElements()) {
        NetworkInterface nic = networkInterface.nextElement();
        if (nic.isUp() && !nic.isLoopback()) {
            Enumeration<InetAddress> inet = nic.getInetAddresses();
            while (inet.hasMoreElements()) {
                InetAddress addr = inet.nextElement();
                if (addr instanceof Inet4Address
                        && !addr.isLinkLocalAddress()) {
                    return addr.getHostAddress();
                }else if (addr instanceof Inet6Address
                        && !addr.isLinkLocalAddress()) {
                    /*
                    We save last seen IPv6 address which we will return
                    if we do not find any interface with IPv4 address.
                    */
                    ipv6AddrStr = addr.getHostAddress();
                }
            }
        }
    }
    return ipv6AddrStr;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:JMXServiceURL.java

示例9: ipVersionMatch

import java.net.Inet6Address; //導入依賴的package包/類
private boolean ipVersionMatch(InetAddress addr) {
    if (opts.ipVersion() != null) {
        switch (opts.ipVersion()) {
            case V4: {
                return addr instanceof Inet4Address;
            }
            case V6: {
                return addr instanceof Inet6Address;
            }
            default: {
                throw new IllegalStateException("Unexpected IP version type: " + opts.ipVersion());
            }
        }
    }

    return true;
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:18,代碼來源:AddressPattern.java

示例10: MulticastSeedNodeProvider

import java.net.Inet6Address; //導入依賴的package包/類
/**
 * Constructs new instance.
 *
 * @param cfg Configuration.
 *
 * @throws UnknownHostException If failed to resolve multicast group address.
 */
public MulticastSeedNodeProvider(MulticastSeedNodeProviderConfig cfg) throws UnknownHostException {
    ConfigCheck check = ConfigCheck.get(getClass());

    check.notNull(cfg, "configuration");
    check.positive(cfg.getPort(), "port");
    check.nonNegative(cfg.getTtl(), "TTL");
    check.notEmpty(cfg.getGroup(), "multicast group");
    check.positive(cfg.getInterval(), "discovery interval");
    check.positive(cfg.getWaitTime(), "wait time");
    check.that(cfg.getInterval() < cfg.getWaitTime(), "discovery interval must be greater than wait time "
        + "[discovery-interval=" + cfg.getInterval() + ", wait-time=" + cfg.getWaitTime() + ']');

    InetAddress groupAddress = InetAddress.getByName(cfg.getGroup());

    check.isTrue(groupAddress.isMulticastAddress(), "address is not a multicast address [address=" + groupAddress + ']');

    group = new InetSocketAddress(groupAddress, cfg.getPort());
    ttl = cfg.getTtl();
    interval = cfg.getInterval();
    waitTime = cfg.getWaitTime();
    loopBackDisabled = cfg.isLoopBackDisabled();

    ipVer = group.getAddress() instanceof Inet6Address ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4;
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:32,代碼來源:MulticastSeedNodeProvider.java

示例11: main

import java.net.Inet6Address; //導入依賴的package包/類
public static void main(String... args) throws Exception {
    NetworkConfiguration.printSystemConfiguration(out);

    NetworkConfiguration nc = NetworkConfiguration.probe();
    String list;
    list = nc.ip4MulticastInterfaces()
              .map(NetworkInterface::getName)
              .collect(joining(" "));
    out.println("ip4MulticastInterfaces: " +  list);

    list = nc.ip4Addresses()
              .map(Inet4Address::toString)
              .collect(joining(" "));
    out.println("ip4Addresses: " +  list);

    list = nc.ip6MulticastInterfaces()
              .map(NetworkInterface::getName)
              .collect(joining(" "));
    out.println("ip6MulticastInterfaces: " +  list);

    list = nc.ip6Addresses()
              .map(Inet6Address::toString)
              .collect(joining(" "));
    out.println("ip6Addresses: " +  list);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:NetworkConfigurationProbe.java

示例12: addDnsServer

import java.net.Inet6Address; //導入依賴的package包/類
private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, InetAddress address) throws UnknownHostException {
    int size = dnsServers.size();
    size++;
    if (address instanceof Inet6Address && ipv6Template == null) {
        Log.i(TAG, "addDnsServer: Ignoring DNS server " + address);
    } else if (address instanceof Inet4Address) {
        String alias = String.format(format, size + 1);
        dnsServers.put(alias, address.getHostAddress());
        builder.addRoute(alias, 32);
        return InetAddress.getByName(alias);
    } else if (address instanceof Inet6Address) {
        ipv6Template[ipv6Template.length - 1] = (byte) (size + 1);
        InetAddress i6addr = Inet6Address.getByAddress(ipv6Template);
        dnsServers.put(i6addr.getHostAddress(), address.getHostAddress());
        return i6addr;
    }
    return null;
}
 
開發者ID:iTXTech,項目名稱:Daedalus,代碼行數:19,代碼來源:DaedalusVpnService.java

示例13: writeTo

import java.net.Inet6Address; //導入依賴的package包/類
@Override
public void writeTo(DataOutput out) throws Exception {
  if (ip_addr != null) {
    byte[] address = ip_addr.getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6)
    out.writeByte(address.length); // 1 byte
    out.write(address, 0, address.length);
    if (ip_addr instanceof Inet6Address)
      out.writeInt(((Inet6Address) ip_addr).getScopeId());
  } else {
    out.writeByte(0);
  }
  out.writeShort(port);
  out.writeInt(vmViewId);
  out.writeLong(mostSigBits);
  out.writeLong(leastSigBits);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:17,代碼來源:JGAddress.java

示例14: send

import java.net.Inet6Address; //導入依賴的package包/類
public boolean send(V2GTPMessage message, Inet6Address udpClientAddress, int udpClientPort) {
	 byte[] v2gTPMessage = message.getMessage();
	// Set up the UDP packet containing the V2GTP message to be sent to the UDP client
	DatagramPacket udpServerPacket = new DatagramPacket(v2gTPMessage, 
														v2gTPMessage.length,
														udpClientAddress,
														udpClientPort);
	
	// Send the response to the UDP client
	try {
		udpServerSocket.send(udpServerPacket);
		getLogger().debug("Message sent");
		
		return true;
	} catch (IOException e) {
		getLogger().error("UDP response failed (IOException) while trying to send message!", e);
		return false;
	}
}
 
開發者ID:V2GClarity,項目名稱:RISE-V2G,代碼行數:20,代碼來源:UDPServer.java

示例15: setData

import java.net.Inet6Address; //導入依賴的package包/類
public void setData(InetAddress data) {
	if (data instanceof Inet4Address) {
		this.addressType = ADDRESS_TYPE_IPv4;
		this.address = data;
		byteData = new byte[6];
		byteData[1] = ADDRESS_TYPE_IPv4;
		System.arraycopy(data.getAddress(), 0, byteData, 2, 4);
		addDataLength(6);
	} else if (data instanceof Inet6Address) {
		this.addressType = ADDRESS_TYPE_IPv6;
		this.address = data;
		byteData = new byte[18];
		byteData[1] = ADDRESS_TYPE_IPv6;
		System.arraycopy(data.getAddress(), 0, byteData, 2, 16);
		addDataLength(18);
	} else {
		// TODO: Throw Custom Error
	}
}
 
開發者ID:mustafabayar,項目名稱:EasyDiameter,代碼行數:20,代碼來源:AddressAVP.java


注:本文中的java.net.Inet6Address類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。