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


Java InetAddress.getByName方法代码示例

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


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

示例1: main

import java.net.InetAddress; //导入方法依赖的package包/类
public static void main(String[] args) {
    if (args.length != 4) {
        throw new RuntimeException(
                "Test failed. usage: java JMXInterfaceBindingTest <BIND_ADDRESS> <JMX_PORT> <RMI_PORT> {true|false}");
    }
    int jmxPort = parsePortFromString(args[1]);
    int rmiPort = parsePortFromString(args[2]);
    boolean useSSL = Boolean.parseBoolean(args[3]);
    String strBindAddr = args[0];
    System.out.println(
            "DEBUG: Running test for triplet (hostname,jmxPort,rmiPort) = ("
                    + strBindAddr + "," + jmxPort + "," + rmiPort + "), useSSL = " + useSSL);
    InetAddress bindAddress;
    try {
        bindAddress = InetAddress.getByName(args[0]);
    } catch (UnknownHostException e) {
        throw new RuntimeException("Test failed. Unknown ip: " + args[0]);
    }
    JMXAgentInterfaceBinding test = new JMXAgentInterfaceBinding(bindAddress,
            jmxPort, rmiPort, useSSL);
    test.startEndpoint(); // Expect for main test to terminate process
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JMXAgentInterfaceBinding.java

示例2: startClient

import java.net.InetAddress; //导入方法依赖的package包/类
public void startClient()
{
   try // connect to server and get streams
   {
      // make connection to server
      connection = new Socket(
         InetAddress.getByName(ticTacToeHost), 12345);

      // get streams for input and output
      input = new Scanner(connection.getInputStream());
      output = new Formatter(connection.getOutputStream());
   } 
   catch (IOException ioException)
   {
      ioException.printStackTrace();         
   } 

   // create and start worker thread for this client
   ExecutorService worker = Executors.newFixedThreadPool(1);
   worker.execute(this); // execute client
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:22,代码来源:TicTacToeClient.java

示例3: write

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Writes the message to the stream.
 * 
 * @param out
 *            Output stream to which message should be written.
 */
public void write(OutputStream out) throws SocksException, IOException {
	if (data == null) {
		Socks5Message msg;

		if (addrType == SOCKS_ATYP_DOMAINNAME) {
			msg = new Socks5Message(command, host, port);
		} else {
			if (ip == null) {
				try {
					ip = InetAddress.getByName(host);
				} catch (final UnknownHostException uh_ex) {
					throw new SocksException(
							SocksProxyBase.SOCKS_JUST_ERROR);
				}
			}
			msg = new Socks5Message(command, ip, port);
		}
		data = msg.data;
	}
	out.write(data);
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4Android,代码行数:28,代码来源:Socks5Message.java

示例4: extractRemoteIp

import java.net.InetAddress; //导入方法依赖的package包/类
private String extractRemoteIp(HttpServletRequest request) {
    String forwardedHeader = request.getHeader("x-forwarded-for");

    if (forwardedHeader != null) {
        String[] addresses = forwardedHeader.split("[,]");

        for (String address : addresses) {
            try {
                InetAddress inetAddress = InetAddress.getByName(address);

                if (!inetAddress.isSiteLocalAddress()) {
                    return inetAddress.getHostAddress();
                }
            } catch (UnknownHostException e) {
                LOGGER.debug("Failed to resolve IP for address: {}", address);
            }
        }
    }

    return request.getRemoteAddr();
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:22,代码来源:MainResource.java

示例5: getLocalHost

import java.net.InetAddress; //导入方法依赖的package包/类
public static InetAddress getLocalHost() {
    String addr = prp.getProperty( "jcifs.smb.client.laddr" );

    if (addr != null) {
        try {
            return InetAddress.getByName( addr );
        } catch( UnknownHostException uhe ) {
            if( log.level > 0 ) {
                log.println( "Ignoring jcifs.smb.client.laddr address: " + addr );
                uhe.printStackTrace( log );
            }
        }
    }

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

示例6: testCaching

import java.net.InetAddress; //导入方法依赖的package包/类
@Test
public void testCaching() {
  Configuration conf = new Configuration();
  conf.setClass(
    CommonConfigurationKeysPublic.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
    MyResolver.class, DNSToSwitchMapping.class);
  RackResolver.init(conf);
  try {
    InetAddress iaddr = InetAddress.getByName("host1");
    MyResolver.resolvedHost1 = iaddr.getHostAddress();
  } catch (UnknownHostException e) {
    // Ignore if not found
  }
  Node node = RackResolver.resolve("host1");
  Assert.assertEquals("/rack1", node.getNetworkLocation());
  node = RackResolver.resolve("host1");
  Assert.assertEquals("/rack1", node.getNetworkLocation());
  node = RackResolver.resolve(invalidHost);
  Assert.assertEquals(NetworkTopology.DEFAULT_RACK, node.getNetworkLocation());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestRackResolver.java

示例7: HttpProxyCacheServer

import java.net.InetAddress; //导入方法依赖的package包/类
private HttpProxyCacheServer(Config config) {
    this.config = checkNotNull(config);
    try {
        InetAddress inetAddress = InetAddress.getByName(PROXY_HOST);
        this.serverSocket = new ServerSocket(0, 8, inetAddress);
        this.port = serverSocket.getLocalPort();
        IgnoreHostProxySelector.install(PROXY_HOST, port);
        CountDownLatch startSignal = new CountDownLatch(1);
        this.waitConnectionThread = new Thread(new WaitRequestsRunnable(startSignal));
        this.waitConnectionThread.start();
        startSignal.await(); // freeze thread, wait for server starts
        this.pinger = new Pinger(PROXY_HOST, port);
        LOG.info("Proxy cache server started. Is it alive? " + isAlive());
    } catch (IOException | InterruptedException e) {
        socketProcessor.shutdown();
        throw new IllegalStateException("Error starting local proxy server", e);
    }
}
 
开发者ID:Achenglove,项目名称:AndroidVideoCache,代码行数:19,代码来源:HttpProxyCacheServer.java

示例8: testDecrementIPv4

import java.net.InetAddress; //导入方法依赖的package包/类
public void testDecrementIPv4() throws UnknownHostException {
  InetAddress address660 = InetAddress.getByName("172.24.66.0");
  InetAddress address66255 = InetAddress.getByName("172.24.66.255");
  InetAddress address670 = InetAddress.getByName("172.24.67.0");

  InetAddress address = address670;
  address = InetAddresses.decrement(address);

  assertEquals(address66255, address);

  for (int i = 0; i < 255; i++) {
    address = InetAddresses.decrement(address);
  }
  assertEquals(address660, address);

  InetAddress address0000 = InetAddress.getByName("0.0.0.0");
  address = address0000;
  try {
    address = InetAddresses.decrement(address);
    fail();
  } catch (IllegalArgumentException expected) {}
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:23,代码来源:InetAddressesTest.java

示例9: scaniprange2fun

import java.net.InetAddress; //导入方法依赖的package包/类
public void scaniprange2fun() {
   	int ipthreadnums = Integer.parseInt(ipthreads.getText().trim());
   	String striii;
	//System.out.println(tip2);
	InetAddress tipordomain2 = null;
	//System.out.println(ipordomain.getText().trim());
	try {
		tipordomain2 = InetAddress.getByName(ipordomain.getText().trim());
	} catch (UnknownHostException e1) {
		// TODO Auto-generated catch block
		//e1.printStackTrace();
	}
	String tip2 = tipordomain2.getHostAddress();
	//System.out.print(tip2);
	for(int iii=1;iii<=254;iii++) {
		striii = Integer.toString(iii);
		Lsaipscan.Scaniprange2.allipp.offer(tip2.split("\\.")[0]+"."+tip2.split("\\.")[1]+"."+tip2.split("\\.")[2]+"."+striii);
		//System.out.print(tip2.split("\\.")[0]+tip2.split("\\.")[1]+"."+tip2.split("\\.")[2]+striii);
	}
	
	iparea.append("----------------Total ip nums: 254------------------\n");
	
	   
	   ExecutorService executor = Executors.newFixedThreadPool(ipthreadnums);
	   for (int i = 0; i < ipthreadnums; i++) {
		   Scaniprange2 scaniprange2 = new Scaniprange2();
           executor.execute(scaniprange2);
        }
	   executor.shutdown();
        try {
            while (!executor.isTerminated()) {
                Thread.sleep(1000);
            }
        } catch (Exception e2) {
            //e2.printStackTrace();
        }
    iparea.append("----------------Over!!!------------------\n");
}
 
开发者ID:theLSA,项目名称:lsascan_v1.0_linux,代码行数:39,代码来源:Lsascan_v1_frame.java

示例10: startThread

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Creates a new Thread object from this class and starts running
 */
public void startThread()
{
    if (0 == this.rconPassword.length())
    {
        this.logWarning("No rcon password set in \'" + this.server.getSettingsFilename() + "\', rcon disabled!");
    }
    else if (0 < this.rconPort && 65535 >= this.rconPort)
    {
        if (!this.running)
        {
            try
            {
                this.serverSocket = new ServerSocket(this.rconPort, 0, InetAddress.getByName(this.hostname));
                this.serverSocket.setSoTimeout(500);
                super.startThread();
            }
            catch (IOException ioexception)
            {
                this.logWarning("Unable to initialise rcon on " + this.hostname + ":" + this.rconPort + " : " + ioexception.getMessage());
            }
        }
    }
    else
    {
        this.logWarning("Invalid rcon port " + this.rconPort + " found in \'" + this.server.getSettingsFilename() + "\', rcon disabled!");
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:31,代码来源:RConThreadMain.java

示例11: setGroup

import java.net.InetAddress; //导入方法依赖的package包/类
public static void setGroup(String group) {
	try {
		TiandeMulticastSocket.group = InetAddress.getByName(group);
	} catch (UnknownHostException e) {
		e.printStackTrace();
	}
}
 
开发者ID:lmd,项目名称:multicast,代码行数:8,代码来源:TiandeMulticastSocket.java

示例12: unicast

import java.net.InetAddress; //导入方法依赖的package包/类
private void unicast(String msg, String host) {
    if (logger.isInfoEnabled()) {
        logger.info("Send unicast message: " + msg + " to " + host + ":" + mutilcastPort);
    }
    try {
        byte[] data = (msg + "\n").getBytes();
        DatagramPacket hi = new DatagramPacket(data, data.length, InetAddress.getByName(host), mutilcastPort);
        mutilcastSocket.send(hi);
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:13,代码来源:MulticastRegistry.java

示例13: getAddressByName

import java.net.InetAddress; //导入方法依赖的package包/类
static
InetAddress getAddressByName(String host) {
  try {
    return InetAddress.getByName(host);
  } catch(Exception e) {
    if (e instanceof InterruptedIOException || e instanceof InterruptedException) {
        Thread.currentThread().interrupt();
    }
    LogLog.error("Could not find address of ["+host+"].", e);
    return null;
  }
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:13,代码来源:SyslogTcpAppender.java

示例14: testIPChange

import java.net.InetAddress; //导入方法依赖的package包/类
@Test
public void testIPChange() throws Exception
{
    UUID uuid = UUID.fromString("abd86e8a-cf47-11e7-abc4-cec278b6b50a");
    byte d1[] = ("[{ \"service\":\"DATABASE\", \"serverid\":\""+uuid+"\", \"data\":{\"hostname\": \"d1\"}}]").getBytes();
    InetAddress a1 = InetAddress.getByName("192.168.1.10");
    InetAddress a2 = InetAddress.getByName("192.168.1.20");

    totest.addServiceListener((serverid, service, jsondata, up) -> {
        System.out.println(serverid + ", " + service + ", " + jsondata + ", " + up);
        if (up) {
            activeuuid = serverid;
            activeip = (InetAddress)jsondata.get("ip");
        } else {
            activeuuid = null;
            activeip = null;
        }
    });

    // message with a1 address
    totest.processNetworkData(a1, d1, d1.length);
    Assert.assertEquals(uuid, activeuuid);
    Assert.assertEquals(a1, activeip);

    // message with a2 addrses
    totest.processNetworkData(a2, d1, d1.length);
    Assert.assertEquals(uuid, activeuuid);
    Assert.assertEquals(a2, activeip);

    // now check a timeout
    Thread.sleep(200);
    Assert.assertEquals(uuid, activeuuid);
    Assert.assertEquals(a2, activeip);

    totest.checkForTimeouts();
    Assert.assertEquals(null, activeuuid);
    Assert.assertEquals(null, activeip);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:39,代码来源:DiscoveryTest.java

示例15: createServerSocket

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Create a server socket.
 * @param serviceUrl jmx service url
 * @return server socket
 * @throws IOException if an I/O error occurs when creating the socket
 */
@Override
public ServerSocket createServerSocket(final JMXServiceURL serviceUrl) throws IOException {
    final InetAddress host = InetAddress.getByName(serviceUrl.getHost());
    final SSLServerSocket baseSslServerSocket = (SSLServerSocket) sslContext.getServerSocketFactory()
            .createServerSocket(serviceUrl.getPort(), 0, host);

    LOGGER.log(Level.FINE, "Created server socket");
    return baseSslServerSocket;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:16,代码来源:SystemSslSocketFactory.java


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