IT. Expert System.

Android Reference

NetworkUtils


android.net

Class NetworkUtils



  • public class NetworkUtils
    extends Object
    Native methods for managing network interfaces.
    • Field Detail

      • RESET_IPV4_ADDRESSES

        public static final int RESET_IPV4_ADDRESSES
        Setting bit 0 indicates reseting of IPv4 addresses required
        See Also:
        Constant Field Values
      • RESET_IPV6_ADDRESSES

        public static final int RESET_IPV6_ADDRESSES
        Setting bit 1 indicates reseting of IPv4 addresses required
        See Also:
        Constant Field Values
      • RESET_ALL_ADDRESSES

        public static final int RESET_ALL_ADDRESSES
        Reset all addresses
        See Also:
        Constant Field Values
    • Constructor Detail

      • NetworkUtils

        public NetworkUtils()
    • Method Detail

      • enableInterface

        public static int enableInterface(String interfaceName)
        Bring the named network interface up.
      • disableInterface

        public static int disableInterface(String interfaceName)
        Bring the named network interface down.
      • resetConnections

        public static int resetConnections(String interfaceName,
                           int mask)
        Reset IPv6 or IPv4 sockets that are connected via the named interface.
        Parameters:
        interfaceName - is the interface to reset
        mask - RESET_IPV4_ADDRESSES and RESET_IPV6_ADDRESSES
      • runDhcp

        public static boolean runDhcp(String interfaceName,
                      DhcpInfoInternal ipInfo)
        Start the DHCP client daemon, in order to have it request addresses for the named interface, and then configure the interface with those addresses. This call blocks until it obtains a result (either success or failure) from the daemon.
        Parameters:
        interfaceName - the name of the interface to configure
        ipInfo - if the request succeeds, this object is filled in with the IP address information.
        Returns:
        true for success, false for failure
      • runDhcpRenew

        public static boolean runDhcpRenew(String interfaceName,
                           DhcpInfoInternal ipInfo)
        Initiate renewal on the Dhcp client daemon. This call blocks until it obtains a result (either success or failure) from the daemon.
        Parameters:
        interfaceName - the name of the interface to configure
        ipInfo - if the request succeeds, this object is filled in with the IP address information.
        Returns:
        true for success, false for failure
      • stopDhcp

        public static boolean stopDhcp(String interfaceName)
        Shut down the DHCP client daemon.
        Parameters:
        interfaceName - the name of the interface for which the daemon should be stopped
        Returns:
        true for success, false for failure
      • releaseDhcpLease

        public static boolean releaseDhcpLease(String interfaceName)
        Release the current DHCP lease.
        Parameters:
        interfaceName - the name of the interface for which the lease should be released
        Returns:
        true for success, false for failure
      • getDhcpError

        public static String getDhcpError()
        Return the last DHCP-related error message that was recorded.

        NOTE: This string is not localized, but currently it is only used in logging.

        Returns:
        the most recent error message, if any
      • intToInetAddress

        public static InetAddress intToInetAddress(int hostAddress)
        Convert a IPv4 address from an integer to an InetAddress.
        Parameters:
        hostAddress - an int corresponding to the IPv4 address in network byte order
      • inetAddressToInt

        public static int inetAddressToInt(InetAddress inetAddr)
                                    throws IllegalArgumentException
        Convert a IPv4 address from an InetAddress to an integer
        Parameters:
        inetAddr - is an InetAddress corresponding to the IPv4 address
        Returns:
        the IP address as an integer in network byte order
        Throws:
        IllegalArgumentException
      • prefixLengthToNetmaskInt

        public static int prefixLengthToNetmaskInt(int prefixLength)
                                            throws IllegalArgumentException
        Convert a network prefix length to an IPv4 netmask integer
        Parameters:
        prefixLength -
        Returns:
        the IPv4 netmask as an integer in network byte order
        Throws:
        IllegalArgumentException
      • netmaskIntToPrefixLength

        public static int netmaskIntToPrefixLength(int netmask)
        Convert a IPv4 netmask integer to a prefix length
        Parameters:
        netmask - as an integer in network byte order
        Returns:
        the network prefix length
      • numericToInetAddress

        public static InetAddress numericToInetAddress(String addrString)
                                                throws IllegalArgumentException
        Create an InetAddress from a string where the string must be a standard representation of a V4 or V6 address. Avoids doing a DNS lookup on failure but it will throw an IllegalArgumentException in that case.
        Parameters:
        addrString -
        Returns:
        the InetAddress
        Throws:
        IllegalArgumentException
      • getNetworkPart

        public static InetAddress getNetworkPart(InetAddress address,
                                 int prefixLength)
        Get InetAddress masked with prefixLength. Will never return null.
        Parameters:
        IP - address which will be masked with specified prefixLength
        prefixLength - the prefixLength used to mask the IP
      • addressTypeMatches

        public static boolean addressTypeMatches(InetAddress left,
                                 InetAddress right)
        Check if IP address type is consistent between two InetAddress.
        Returns:
        true if both are the same type. False otherwise.
      • hexToInet6Address

        public static InetAddress hexToInet6Address(String addrHexString)
                                             throws IllegalArgumentException
        Convert a 32 char hex string into a Inet6Address. throws a runtime exception if the string isn't 32 chars, isn't hex or can't be made into an Inet6Address
        Parameters:
        addrHexString - a 32 character hex string representing an IPv6 addr
        Returns:
        addr an InetAddress representation for the string
        Throws:
        IllegalArgumentException
      • makeStrings

        public static String[] makeStrings(Collection<InetAddress> addrs)
        Create a string array of host addresses from a collection of InetAddresses
        Parameters:
        addrs - a Collection of InetAddresses
        Returns:
        an array of Strings containing their host addresses
      • trimV4AddrZeros

        public static String trimV4AddrZeros(String addr)
        Trim leading zeros from IPv4 address strings Our base libraries will interpret that as octel.. Must leave non v4 addresses and host names alone. For example, 192.168.000.010 -> 192.168.0.10 TODO - fix base libraries and remove this function
        Parameters:
        addr - a string representing an ip addr
        Returns:
        a string propertly trimmed


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 193 / 158674446. Delta: 0.03347 с