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


Java Inet4Address类代码示例

本文整理汇总了Java中java.net.Inet4Address的典型用法代码示例。如果您正苦于以下问题:Java Inet4Address类的具体用法?Java Inet4Address怎么用?Java Inet4Address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getEmbeddedIPv4ClientAddress

import java.net.Inet4Address; //导入依赖的package包/类
/**
 * Examines the Inet6Address to extract the embedded IPv4 client address if the InetAddress is an
 * IPv6 address of one of the specified address types that contain an embedded IPv4 address.
 *
 * <p>NOTE: ISATAP addresses are explicitly excluded from this method due to their trivial
 * spoofability. With other transition addresses spoofing involves (at least) infection of one's
 * BGP routing table.
 *
 * @param ip {@link Inet6Address} to be examined for embedded IPv4 client address
 * @return {@link Inet4Address} of embedded IPv4 client address
 * @throws IllegalArgumentException if the argument does not have a valid embedded IPv4 address
 */
public static Inet4Address getEmbeddedIPv4ClientAddress(Inet6Address ip) {
  if (isCompatIPv4Address(ip)) {
    return getCompatIPv4Address(ip);
  }

  if (is6to4Address(ip)) {
    return get6to4IPv4Address(ip);
  }

  if (isTeredoAddress(ip)) {
    return getTeredoInfo(ip).getClient();
  }

  throw formatIllegalArgumentException("'%s' has no embedded IPv4 address.", toAddrString(ip));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:28,代码来源:InetAddresses.java

示例2: testIsAuthenticationDialogSuppressed

import java.net.Inet4Address; //导入依赖的package包/类
public void testIsAuthenticationDialogSuppressed() throws Exception {
    final boolean[] suppressed = new boolean[1];
    Authenticator.setDefault(new Authenticator() {

        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            suppressed[0] = NetworkSettings.isAuthenticationDialogSuppressed();
            return super.getPasswordAuthentication();
        }
    });

    Callable<Void> callable = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Authenticator.requestPasswordAuthentication("wher.ev.er", Inet4Address.getByName("1.2.3.4"), 1234, "http", null, "http");
            return null;
        }
    };
    NetworkSettings.suppressAuthenticationDialog(callable);
    assertTrue(suppressed[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:NetworkSettingsTest.java

示例3: pickInetAddress

import java.net.Inet4Address; //导入依赖的package包/类
protected static InetAddress pickInetAddress(Iterable<InetAddress> sortedList, IpAddressUtils.IpTypePreference ipTypePref) {
    IpAddressUtils.IpTypePreference pref = getIpTypePreferenceResolved(ipTypePref);
    for (InetAddress ipAddress : sortedList) {
        if (pref == IpAddressUtils.IpTypePreference.ANY_IPV4_PREF  || pref == IpAddressUtils.IpTypePreference.ANY_IPV6_PREF) {
            return ipAddress;
        }
        if (ipAddress instanceof Inet4Address) {
            if (pref == IpAddressUtils.IpTypePreference.IPV4_ONLY) {
                return ipAddress;
            }
        }
        if (ipAddress instanceof Inet6Address) {
            if (pref == IpAddressUtils.IpTypePreference.IPV6_ONLY) {
                return ipAddress;
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:IpAddressUtilsFilter.java

示例4: filterInetAddresses

import java.net.Inet4Address; //导入依赖的package包/类
protected static @NonNull List<InetAddress> filterInetAddresses(Iterable<InetAddress> list, IpAddressUtils.IpTypePreference ipTypePref) {
    IpAddressUtils.IpTypePreference pref = getIpTypePreferenceResolved(ipTypePref);
    List<InetAddress> newList = new ArrayList<>();
    if (list != null) {
        for (InetAddress ipAddress : list) {
            if (pref == IpAddressUtils.IpTypePreference.ANY_IPV4_PREF || pref == IpAddressUtils.IpTypePreference.ANY_IPV6_PREF) {
                newList.add(ipAddress);
            } else {
                if ((ipAddress instanceof Inet4Address) && (pref == IpAddressUtils.IpTypePreference.IPV4_ONLY)) {
                    newList.add(ipAddress);
                }
                if ((ipAddress instanceof Inet6Address) && (pref == IpAddressUtils.IpTypePreference.IPV6_ONLY)) {
                    newList.add(ipAddress);
                }
            }
        }
    }
    if (pref == IpAddressUtils.IpTypePreference.ANY_IPV4_PREF) {
        IpAddressUtils.sortIpAddressesShallow(newList,true);
    }
    if (pref == IpAddressUtils.IpTypePreference.ANY_IPV6_PREF) {
        IpAddressUtils.sortIpAddressesShallow(newList,false);
    }
    return newList;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:IpAddressUtilsFilter.java

示例5: GetHostIp

import java.net.Inet4Address; //导入依赖的package包/类
/**
 * 获取ip地址方法
 * @return
 */
public static String GetHostIp() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface
                .getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> ipAddr = intf.getInetAddresses(); ipAddr
                    .hasMoreElements();) {
                InetAddress inetAddress = ipAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                    //if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet6Address) {
                    return inetAddress.getHostAddress().toString();
                }

            }
        }
    } catch (SocketException ex) {
    } catch (Exception e) {
    }
    return null;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:25,代码来源:IpUtils.java

示例6: getIpAddress

import java.net.Inet4Address; //导入依赖的package包/类
public static String getIpAddress() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && (inetAddress instanceof Inet4Address)) { // we get both ipv4 and ipv6, we want ipv4
                    return inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException e) {
        Log.e(TAG,"getIpAddress", e);
    }

    return null;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:18,代码来源:ArchosUtils.java

示例7: getTeredoInfo

import java.net.Inet4Address; //导入依赖的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:paul-hammant,项目名称:googles-monorepo-demo,代码行数:28,代码来源:InetAddresses.java

示例8: importContact

import java.net.Inet4Address; //导入依赖的package包/类
@Override
public DHTPluginContact
importContact(
	InetSocketAddress				address,
	byte							version )
{
	if ( !isEnabled()){

		throw( new RuntimeException( "DHT isn't enabled" ));
	}

	InetAddress contact_address = address.getAddress();

	for ( DHTPluginImpl dht: dhts ){

		InetAddress dht_address = dht.getLocalAddress().getAddress().getAddress();

		if ( 	( contact_address instanceof Inet4Address && dht_address instanceof Inet4Address ) ||
				( contact_address instanceof Inet6Address && dht_address instanceof Inet6Address )){

			return( dht.importContact( address, version ));
		}
	}

	return( null );
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:27,代码来源:DHTPlugin.java

示例9: getIpv4Address

import java.net.Inet4Address; //导入依赖的package包/类
public static String getIpv4Address() {
    try {
        for (Enumeration<NetworkInterface> enNetI = NetworkInterface.getNetworkInterfaces(); enNetI.hasMoreElements(); ) {
            NetworkInterface netI = enNetI.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = netI.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return "";
}
 
开发者ID:jiajieshen,项目名称:AndroidDevSamples,代码行数:17,代码来源:NetworkUtil.java

示例10: getAddresses

import java.net.Inet4Address; //导入依赖的package包/类
/**
 * Returns a list of all the addresses on the system.
 * @param  inclLoopback
 *         if {@code true}, include the loopback addresses
 * @param  ipv4Only
 *         it {@code true}, only IPv4 addresses will be included
 */
static List<InetAddress> getAddresses(boolean inclLoopback,
                                      boolean ipv4Only)
    throws SocketException {
    ArrayList<InetAddress> list = new ArrayList<InetAddress>();
    Enumeration<NetworkInterface> nets =
             NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netInf : Collections.list(nets)) {
        Enumeration<InetAddress> addrs = netInf.getInetAddresses();
        for (InetAddress addr : Collections.list(addrs)) {
            if (!list.contains(addr) &&
                    (inclLoopback ? true : !addr.isLoopbackAddress()) &&
                    (ipv4Only ? (addr instanceof Inet4Address) : true)) {
                list.add(addr);
            }
        }
    }

    return list;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:Util.java

示例11: valueOf

import java.net.Inet4Address; //导入依赖的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

示例12: getLocalIpAddress

import java.net.Inet4Address; //导入依赖的package包/类
public static String getLocalIpAddress() {
    try {
        String localIpAddress = Collections.list(NetworkInterface.getNetworkInterfaces()).stream()
                .flatMap(networkInterface -> Collections.list(networkInterface.getInetAddresses()).stream())
                .filter(inetAddress -> inetAddress instanceof Inet4Address && inetAddress.getAddress()[0] != 127)
                .map(InetAddress::getHostAddress)
                .findFirst()
                .orElseThrow(AssertionError::new);

        logger.debug("localIpAddress: {}", localIpAddress); // TODO not even in debug.

        return localIpAddress;
    } catch (SocketException e) {
        // should never happen
        throw new AssertionError();
    }
}
 
开发者ID:membrane,项目名称:kubernetes-client,代码行数:18,代码来源:Util.java

示例13: pingButtonActionPerformed

import java.net.Inet4Address; //导入依赖的package包/类
private void pingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pingButtonActionPerformed
       String host = hostTF.getText();
     try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        InetAddress adr = Inet4Address.getByName(host);
        try{
            adr.isReachable(3000);
            JOptionPane.showMessageDialog(this, host+" is reachable, but it may not be the SpiNNaker!");
        }catch(IOException notReachable){
            JOptionPane.showMessageDialog(this, host+" is not reachable: "+notReachable.toString(), "Not reachable", JOptionPane.WARNING_MESSAGE);
        }
    } catch (UnknownHostException ex) {
              JOptionPane.showMessageDialog(this, host+" is unknown host: "+ex.toString(), "Host not found", JOptionPane.WARNING_MESSAGE);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }

}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:19,代码来源:SpiNNaker_InterfaceFactory.java

示例14: setup

import java.net.Inet4Address; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    System.setProperty(ApplicationProperties.PROPERTIES_ROOT_PATH, new File(".").getAbsolutePath() + "/src/test/resources");
    PowerMockito.mockStatic(JwalaUtils.class);
    PowerMockito.when(JwalaUtils.getHostAddress("testServer")).thenReturn(Inet4Address.getLocalHost().getHostAddress());
    PowerMockito.when(JwalaUtils.getHostAddress("testServer2")).thenReturn(Inet4Address.getLocalHost().getHostAddress());

    // It is good practice to start with a clean sheet of paper before each test that is why resourceService is
    // initialized here. This makes sure that unrelated tests don't affect each other.
    MockitoAnnotations.initMocks(this);
    reset(Config.mockHistoryFacadeService);
    reset(Config.mockJvmPersistenceService);
    reset(Config.mockWebServerPersistenceService);
    reset(Config.mockGroupPesistenceService);
    reset(Config.mockAppPersistenceService);

    when(Config.mockJvmPersistenceService.findJvmByExactName(eq("someJvm"))).thenReturn(mock(Jvm.class));
    when(Config.mockRepositoryService.upload(anyString(), any(InputStream.class))).thenReturn("thePath");
}
 
开发者ID:cerner,项目名称:jwala,代码行数:20,代码来源:ResourceServiceImplTest.java

示例15: Authority

import java.net.Inet4Address; //导入依赖的package包/类
/** */
private Authority(
    Optional<String> userName, Optional<String> password,
    Optional<Object> host, int portOrNegOne,
    IDNA.Info info) {
  if (host.isPresent()) {
    Object hostObj = host.get();
    Preconditions.checkArgument(
        hostObj instanceof InternetDomainName
        || hostObj instanceof Inet4Address
        || hostObj instanceof Inet6Address,
        "Invalid host", hostObj);
  }

  this.userName = userName;
  this.password = password;
  this.host = host;
  this.portOrNegOne = portOrNegOne;
  this.info = info;
}
 
开发者ID:OWASP,项目名称:url-classifier,代码行数:21,代码来源:Authority.java


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