本文整理汇总了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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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
}
}