當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。