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


Java InetAddress.getHostAddress方法代码示例

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


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

示例1: resolveAndShuffle

import java.net.InetAddress; //导入方法依赖的package包/类
private List<InetSocketAddress> resolveAndShuffle(Collection<InetSocketAddress> serverAddresses) {
    List<InetSocketAddress> tmpList = new ArrayList<InetSocketAddress>(serverAddresses.size());       
    for (InetSocketAddress address : serverAddresses) {
        try {
            InetAddress ia = address.getAddress();
            String addr = (ia != null) ? ia.getHostAddress() : address.getHostString();
            InetAddress resolvedAddresses[] = InetAddress.getAllByName(addr);
            for (InetAddress resolvedAddress : resolvedAddresses) {
                InetAddress taddr = InetAddress.getByAddress(address.getHostString(), resolvedAddress.getAddress());
                tmpList.add(new InetSocketAddress(taddr, address.getPort()));
            }
        } catch (UnknownHostException ex) {
            LOG.warn("No IP address found for server: {}", address, ex);
        }
    }
    Collections.shuffle(tmpList, sourceOfRandomness);
    return tmpList;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:19,代码来源:StaticHostProvider.java

示例2: checkAcceptPermission

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Verify that the given AccessControlContext has permission to
 * accept this connection.
 */
void checkAcceptPermission(SecurityManager sm,
                           AccessControlContext acc)
{
    /*
     * Note: no need to synchronize on cache-related fields, since this
     * method only gets called from the ConnectionHandler's thread.
     */
    if (sm != cacheSecurityManager) {
        okContext = null;
        authCache = new WeakHashMap<AccessControlContext,
                                    Reference<AccessControlContext>>();
        cacheSecurityManager = sm;
    }
    if (acc.equals(okContext) || authCache.containsKey(acc)) {
        return;
    }
    InetAddress addr = socket.getInetAddress();
    String host = (addr != null) ? addr.getHostAddress() : "*";

    sm.checkAccept(host, socket.getPort());

    authCache.put(acc, new SoftReference<AccessControlContext>(acc));
    okContext = acc;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:TCPTransport.java

示例3: ConnectionBean

import java.net.InetAddress; //导入方法依赖的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:l294265421,项目名称:ZooKeeper,代码行数:19,代码来源:ConnectionBean.java

示例4: getIpAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private String getIpAddress() {
    String ip = "";
    try {
        Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (enumNetworkInterfaces.hasMoreElements()) {

            NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
            Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();

            while (enumInetAddress.hasMoreElements()) {
                InetAddress inetAddress = enumInetAddress.nextElement();

                if (inetAddress.isSiteLocalAddress()) {
                    ip += inetAddress.getHostAddress();
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
        ip += "Something Wrong! " + e.toString() + "\n";
    }
    return ip;
}
 
开发者ID:yuvaraj119,项目名称:WifiChatSharing,代码行数:24,代码来源:MessageActivity.java

示例5: getRemoteIPv4Address

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getRemoteIPv4Address() {
  try {
    List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
    for (NetworkInterface ni : interfaces) {
      List<InetAddress> addresses = Collections.list(ni.getInetAddresses());
      for (InetAddress addr : addresses) {
        if (!addr.isLoopbackAddress()) {
          String strAddr = addr.getHostAddress();
          if(!strAddr.contains(":")) {
            return strAddr.substring(0, strAddr.lastIndexOf(".") + 1) + "255";
          }
        }
      }
    }
  } catch (SocketException e) {
    e.printStackTrace();
  }

  return "255.255.255.255";
}
 
开发者ID:tkrworks,项目名称:JinsMemeBRIDGE-Android,代码行数:21,代码来源:MemeOSC.java

示例6: getRemoteIp

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getRemoteIp(Channel channel) {
    InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.remoteAddress();
    if (inetSocketAddress == null) {
        return "";
    }
    final InetAddress inetAddr = inetSocketAddress.getAddress();
    return (inetAddr != null ? inetAddr.getHostAddress() : inetSocketAddress.getHostName());
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:9,代码来源:ChannelUtil.java

示例7: main

import java.net.InetAddress; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        InetAddress localAddress = InetAddress.getLocalHost();
        String[] hostlist = new String[] {
            localAddress.getHostAddress(), localAddress.getHostName() };

        for (int i = 0; i < hostlist.length; i++) {

            System.setProperty("java.rmi.server.hostname", hostlist[i]);
            Remote impl = new ChangeHostName();
            System.err.println("\ncreated impl extending URO: " + impl);

            Receiver stub = (Receiver) RemoteObject.toStub(impl);
            System.err.println("stub for impl: " + stub);

            System.err.println("invoking method on stub");
            stub.receive(stub);

            UnicastRemoteObject.unexportObject(impl, true);
            System.err.println("unexported impl");

            if (stub.toString().indexOf(hostlist[i]) >= 0) {
                System.err.println("stub's ref contains hostname: " +
                                   hostlist[i]);
            } else {
                throw new RuntimeException(
                    "TEST FAILED: stub's ref doesn't contain hostname: " +
                    hostlist[i]);
            }
        }
        System.err.println("TEST PASSED");
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:ChangeHostName.java

示例8: isValidHostAddress

import java.net.InetAddress; //导入方法依赖的package包/类
private static boolean isValidHostAddress(InetAddress address) {
    if (address == null || address.isLoopbackAddress()) {
        return false;
    }

    String name = address.getHostAddress();
    return (name != null && !EMPTY_IP.equals(name) && !LOCALHOST_IP.equals(name) && IP_PATTERN.matcher(name)
        .matches());
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:10,代码来源:AddressUtils.java

示例9: updateIP

import java.net.InetAddress; //导入方法依赖的package包/类
protected void
updateIP()
{
	InetAddress	latest_ip = buddy.getAdjustedIP();

	if ( latest_ip != null ){

		current_ip	= latest_ip.getHostAddress();

		log( "IP set to " + current_ip );
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:13,代码来源:BuddyPluginTracker.java

示例10: getLocalAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Returns the IP address that this HTTP server instance is bound to.
 * @return String representation of the IP address or <code>null</code> if not running
 */
public String getLocalAddress() {
    InetAddress address = listener.getInetAddress();
    // Ugly work-around for older JDKs
    byte[] octets = address.getAddress();
    if ((octets[0] == 0) 
     && (octets[1] == 0) 
     && (octets[2] == 0) 
     && (octets[3] == 0)) {
        return "localhost"; 
    } else {
        return address.getHostAddress();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:18,代码来源:SimpleHttpServer.java

示例11: addServer

import java.net.InetAddress; //导入方法依赖的package包/类
public synchronized void addServer(String pingResponse, InetAddress ipAddress)
{
    String s = ThreadLanServerPing.getMotdFromPingResponse(pingResponse);
    String s1 = ThreadLanServerPing.getAdFromPingResponse(pingResponse);

    if (s1 != null)
    {
        s1 = ipAddress.getHostAddress() + ":" + s1;
        boolean flag = false;

        for (LanServerInfo lanserverinfo : this.listOfLanServers)
        {
            if (lanserverinfo.getServerIpPort().equals(s1))
            {
                lanserverinfo.updateLastSeen();
                flag = true;
                break;
            }
        }

        if (!flag)
        {
            this.listOfLanServers.add(new LanServerInfo(s, s1));
            this.wasUpdated = true;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:28,代码来源:LanServerDetector.java

示例12: toString

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public String toString()
{
	final InetAddress address = getConnection().getInetAddress();
	if (getState() == LoginClientState.AUTHED_LOGIN)
	{
		return "[" + getAccount() + " (" + (address == null ? "disconnected" : address.getHostAddress()) + ")]";
	}
	return "[" + (address == null ? "disconnected" : address.getHostAddress()) + "]";
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:11,代码来源:L2LoginClient.java

示例13: ClientHandler

import java.net.InetAddress; //导入方法依赖的package包/类
public ClientHandler(Socket socket) {
	this.socket = socket;
	/*
	 * 通过Socket获取远程计算机地址信息 对于服务端而言,远程计算机就是客户端了
	 */
	InetAddress address = socket.getInetAddress();
	// 获取IP地址
	host = address.getHostAddress();
}
 
开发者ID:followwwind,项目名称:javase,代码行数:10,代码来源:Server.java

示例14: getIpAddr

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * 获取计算机的ip地址
 * @return
 */
public static String getIpAddr() {
	String ipAddress = null;
	try {
		InetAddress address = InetAddress.getLocalHost();
		ipAddress = address.getHostAddress();
	} catch (UnknownHostException e) {
		logger.error(e.getMessage(), e);
	}
	return ipAddress;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:15,代码来源:WebUtil.java

示例15: doReverseLookup

import java.net.InetAddress; //导入方法依赖的package包/类
static void doReverseLookup(NetworkInterface netIf) throws SocketException, UnknownHostException {
    for (NetworkInterface subIf : Collections.list(netIf.getSubInterfaces())) {
        Enumeration<InetAddress> subInetAddresses = subIf.getInetAddresses();
        while (subInetAddresses != null && subInetAddresses.hasMoreElements()) {
            InetAddress inetAddress = subInetAddresses.nextElement();
            String reversalString = inetAddress.getHostAddress();
            //should not throw UHE in case of virtual sub interface
            InetAddress.getByName(reversalString);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SubNetworkInterfaceTest.java


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