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


Java InetAddress.getHostName方法代码示例

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


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

示例1: SocksSocket

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Connects to given ip and port using given Proxy server.
 * 
 * @param p
 *            Proxy to use.
 * @param ip
 *            Machine to connect to.
 * @param port
 *            Port to which to connect.
 */
public SocksSocket(SocksProxyBase p, InetAddress ip, int port)
		throws SocksException {
	if (p == null) {
		throw new SocksException(SocksProxyBase.SOCKS_NO_PROXY);
	}
	this.proxy = p.copy();
	this.remoteIP = ip;
	this.remotePort = port;
	this.remoteHost = ip.getHostName();
	if (proxy.isDirect(remoteIP)) {
		doDirect();
	} else {
		processReply(proxy.connect(ip, port));
	}
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4j,代码行数:26,代码来源:SocksSocket.java

示例2: connect

import java.net.InetAddress; //导入方法依赖的package包/类
void connect(InetAddress address, int port) {
   if(this.address == null)
     return;
   try {
     // First, close the previous connection if any.
     cleanUp();
     stw = new SyslogTcpWriter(new Socket(address, port).getOutputStream(), syslogFacility);
   } catch(IOException e) {
     if (e instanceof InterruptedIOException) {
         Thread.currentThread().interrupt();
     }
     String msg = "Could not connect to remote log4j server at ["
+address.getHostName()+"].";
     if(reconnectionDelay > 0) {
       msg += " We will try again later.";
fireConnector(); // fire the connector thread
     } else {
         msg += " We are not retrying.";
         errorHandler.error(msg, e, ErrorCode.GENERIC_FAILURE);
     } 
     LogLog.error(msg);
   }
 }
 
开发者ID:baidu,项目名称:openrasp,代码行数:24,代码来源:SyslogTcpAppender.java

示例3: testRunStarted

import java.net.InetAddress; //导入方法依赖的package包/类
/**
*
* @see org.junit.runner.notification.RunListener#testRunStarted(org.junit.runner.Description)
*/
@Override
public void testRunStarted( Description description ) throws Exception {

    if (log.isDebugEnabled()) { // currently always returns null for Description parameter
        log.debug("testRunStarted(): Called before any test is run. Description of all tests expected: "
                  + description);
    }
    String runNameSysProp = AtsSystemProperties.getPropertyAsString(AtsSystemProperties.TEST_HARNESS__JUNIT_RUN_NAME,
                                                                    "JUnit run(nameless)");

    String hostNameIp = "";
    try {
        InetAddress addr = InetAddress.getLocalHost();
        hostNameIp = addr.getHostName() + "/" + addr.getHostAddress();

    } catch (UnknownHostException uhe) {
        hostNameIp = null;
    }

    logger.startRun(runNameSysProp /* no suite name in JUnit */, CommonConfigurator.getInstance().getOsName(),
                    CommonConfigurator.getInstance().getProductName(),
                    CommonConfigurator.getInstance().getVersionName(),
                    CommonConfigurator.getInstance().getBuildName(), hostNameIp);
    super.testRunStarted(description);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:30,代码来源:AtsJunitTestListener.java

示例4: getHostName

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getHostName(String address) {
  	try {
  		int i = address.indexOf(':');
  		if (i > -1) {
  			address = address.substring(0, i);
  		}
  		String hostname = hostNameCache.get(address);
  		if (hostname != null && hostname.length() > 0) {
  			return hostname;
  		}
  		InetAddress inetAddress = InetAddress.getByName(address);
  		if (inetAddress != null) {
  			hostname = inetAddress.getHostName();
  			hostNameCache.put(address, hostname);
  			return hostname;
  		}
} catch (Throwable e) {
	// ignore
}
return address;
  }
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:22,代码来源:NetUtils.java

示例5: SyslogTcpAppender

import java.net.InetAddress; //导入方法依赖的package包/类
/**
   Connects to remote server at <code>address</code> and <code>port</code>.
*/
public SyslogTcpAppender(InetAddress address, int port, int syslogFacility) {
  this.address = address;
  this.remoteHost = address.getHostName();
  this.port = port;
  this.syslogFacility = syslogFacility;
  this.initSyslogFacilityStr();
  connect(address, port);
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:12,代码来源:SyslogTcpAppender.java

示例6: Socks5Message

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Construct client request or server response.
 * 
 * @param cmd
 *            - Request/Response code.
 * @param ip
 *            - IP field.
 * @paarm port - port field.
 */
public Socks5Message(int cmd, InetAddress ip, int port) {
	super(cmd, ip, port);

	if (ip == null) {
		this.host = "0.0.0.0";
	} else {
		this.host = ip.getHostName();
	}

	this.version = SOCKS_VERSION;

	byte[] addr;

	if (ip == null) {
		addr = new byte[4];
		addr[0] = addr[1] = addr[2] = addr[3] = 0;
	} else {
		addr = ip.getAddress();
	}

	if (addr.length == 4) {
		addrType = SOCKS_ATYP_IPV4;
	} else {
		addrType = SOCKS_ATYP_IPV6;
	}

	data = new byte[6 + addr.length];
	data[0] = (byte) SOCKS_VERSION; // Version
	data[1] = (byte) command; // Command
	data[2] = (byte) 0; // Reserved byte
	data[3] = (byte) addrType; // Address type

	// Put Address
	System.arraycopy(addr, 0, data, 4, addr.length);
	// Put port
	data[data.length - 2] = (byte) (port >> 8);
	data[data.length - 1] = (byte) (port);
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4Android,代码行数:48,代码来源:Socks5Message.java

示例7: getHostnameOrAddress

import java.net.InetAddress; //导入方法依赖的package包/类
public static String getHostnameOrAddress() {
    try {
        final InetAddress addr = InetAddress.getLocalHost();
        return addr.getHostName();
    } catch (UnknownHostException e) {
        try {
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            if (interfaces == null) {
                return "";
            }
            NetworkInterface intf = interfaces.nextElement();
            Enumeration<InetAddress> addresses = intf.getInetAddresses();
            while (addresses.hasMoreElements()) {
                InetAddress address = addresses.nextElement();
                if (address instanceof Inet4Address) {
                    return address.getHostAddress();
                }
            }
            interfaces = NetworkInterface.getNetworkInterfaces();
            while (addresses.hasMoreElements()) {
                return addresses.nextElement().getHostAddress();
            }
            return "";
        } catch (SocketException e1) {
            return "";
        }
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:29,代码来源:ConnectionUtil.java

示例8: getHostname

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Returns the name of the local host.
 *
 * @return The host name
 * @throws UnknownHostException if IP address of a host could not be determined
 */
public static String getHostname() throws UnknownHostException {
    InetAddress inetAddress = InetAddress.getLocalHost();
    String hostName = inetAddress.getHostName();

    assertTrue((hostName != null && !hostName.isEmpty()),
            "Cannot get hostname");

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

示例9: umnt

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public XDR umnt(XDR xdr, XDR out, int xid, InetAddress client) {
  String path = xdr.readString();
  if (LOG.isDebugEnabled()) {
    LOG.debug("MOUNT UMNT path: " + path + " client: " + client);
  }
  
  String host = client.getHostName();
  mounts.remove(new MountEntry(host, path));
  RpcAcceptedReply.getAcceptInstance(xid, new VerifierNone()).write(out);
  return out;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:RpcProgramMountd.java

示例10: isHostAuthenticatedMember

import java.net.InetAddress; //导入方法依赖的package包/类
public boolean isHostAuthenticatedMember ( String ipAddress ) {
	try {
		InetAddress addr = InetAddress.getByName( ipAddress );
		String remoteServerName = addr.getHostName();

		if ( remoteServerName.equals( "127.0.0.1" ) ) {
			remoteServerName = "localhost";
		}

		if ( remoteServerName.contains( "." ) ) {
			remoteServerName = remoteServerName.substring( 0, remoteServerName.indexOf( "." ) );
		}

		if ( remoteServerName.equals( "rtp-someDeveloper-8811" ) && getCurrentLifeCycle().equals( "dev" ) ) {

			logger.warn( "DEVELOPER TESTING: Resolved: {} to host: {}", ipAddress, remoteServerName );
			return true;
		}
		logger.debug( "Resolved: {} to host: {}", ipAddress, remoteServerName );

		return getAllHostsInAllPackagesInCurrentLifecycle().contains( remoteServerName );

	} catch (Exception e) {
		logger.error( "Failed to get hostname" );
	}

	return false;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:29,代码来源:Application.java

示例11: addNewPeer

import java.net.InetAddress; //导入方法依赖的package包/类
public void addNewPeer(Socket pSocket) {
  IllegalArgument.ifNull("Socket", pSocket);
  InetAddress theirAddress = pSocket.getInetAddress();
  String theirName = theirAddress.getHostName();
  String theirIP = theirAddress.getHostAddress();
  String name = theirIP.equals(theirName) ? null : "(Host: " + theirName + ")";
  zPendingPeers.add(pSocket, new PeerInfo(name, theirIP));
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:9,代码来源:PendingPeerManager.java

示例12: process

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final HttpCoreContext corecontext = HttpCoreContext.adapt(context);

    final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT") && ver.lessEquals(HttpVersion.HTTP_1_0)) {
        return;
    }

    if (!request.containsHeader(HTTP.TARGET_HOST)) {
        HttpHost targethost = corecontext.getTargetHost();
        if (targethost == null) {
            final HttpConnection conn = corecontext.getConnection();
            if (conn instanceof HttpInetConnection) {
                // Populate the context with a default HTTP host based on the
                // inet address of the target host
                final InetAddress address = ((HttpInetConnection) conn).getRemoteAddress();
                final int port = ((HttpInetConnection) conn).getRemotePort();
                if (address != null) {
                    targethost = new HttpHost(address.getHostName(), port);
                }
            }
            if (targethost == null) {
                if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
                    return;
                } else {
                    throw new ProtocolException("Target host missing");
                }
            }
        }
        request.addHeader(HTTP.TARGET_HOST, targethost.toHostString());
    }
}
 
开发者ID:gusavila92,项目名称:java-android-websocket-client,代码行数:38,代码来源:RequestTargetHost.java

示例13: localHostName

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Returns the host name for the local host. If the operation is not allowed
 * by the security check, the textual representation of the IP address of
 * the local host is returned instead. If the ip address of the local host
 * cannot be resolved or if there is any other failure, "localhost" is
 * returned as a fallback.
 */
public static String localHostName() {
    try {
        InetAddress localhost = InetAddress.getLocalHost();
        return localhost.getHostName();
    } catch (Exception e) {
        InternalLogFactory.getLog(AwsHostNameUtils.class)
            .debug(
                "Failed to determine the local hostname; fall back to "
                        + "use \"localhost\".", e);
        return "localhost";
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:20,代码来源:AwsHostNameUtils.java

示例14: updateApplicationVariables

import java.net.InetAddress; //导入方法依赖的package包/类
private void updateApplicationVariables ()
		throws UnknownHostException {

	httpdIntegration.updateConstants();

	WAR_DIR = STAGING + CSAP_SERVICE_PACKAGES;
	BUILD_DIR = STAGING + "/build/";
	// Use relative paths to handle all use cases
	CSAP_DEFINITION_FOLDER_FOR_JUNITs = getDefinitionFile()
		.getParentFile()
		.getAbsolutePath();
	InetAddress addr = InetAddress.getLocalHost();

	// Get hostname
	HOST_NAME = addr.getHostName();
	if ( HOST_NAME.indexOf( "." ) != -1 ) {
		// in case of host.somecompany.com, strip off domain
		HOST_NAME = HOST_NAME.substring( 0, HOST_NAME.indexOf( "." ) );
	}

	// hook for testing on eclipse
	logger.info( "Host name is: {}", HOST_NAME );
	if ( isRunningOnDesktop() ) {
		HOST_NAME = "localhost";
		//
		logger.info( "\n\n Did not find STAGING env var,  forcing test mode - setting host to localhost \n\n" );
	}

	if ( isJvmInManagerMode() ) {
		refreshConfigHandleOnlyOnMgrs = refreshConfigPool.scheduleWithFixedDelay(
			new Runnable() {

				@Override
				public void run () {
					updateCache( false );
				}
			}, 10, 10, TimeUnit.SECONDS );
	}
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:40,代码来源:Application.java

示例15: 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:ChangeHostName.java


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