@Override public void run() { // TODO Auto-generated method stub int l4port = 5757; try { ServerSocket ServerSocket = new ServerSocket(l4port); Socket socket = null; do { socket = ServerSocket.accept(); InetAddress remoteIP = socket.getInetAddress(); InputStream is = socket.getInputStream(); Log.v("Deamon", remoteIP.toString()); Log.v("Deamon", is.toString()); } while (socket != null); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Activate this <tt>UDPTerminal</tt>. * * @throws Exception if there is a network failure. */ public synchronized void activate() throws Exception { if (!isActive()) { if (Modbus.debug) CCLog.info( "UDPMasterTerminal::activate()::laddr=:" + m_LocalAddress + ":lport=" + m_LocalPort); if (m_Socket == null) { if (m_LocalAddress != null && m_LocalPort != -1) { m_Socket = new DatagramSocket(m_LocalPort, m_LocalAddress); } else { m_Socket = new DatagramSocket(); m_LocalPort = m_Socket.getLocalPort(); m_LocalAddress = m_Socket.getLocalAddress(); } } if (Modbus.debug) CCLog.info("UDPMasterTerminal::haveSocket():" + m_Socket.toString()); if (Modbus.debug) CCLog.info( "UDPMasterTerminal::laddr=:" + m_LocalAddress.toString() + ":lport=" + m_LocalPort); if (Modbus.debug) CCLog.info( "UDPMasterTerminal::raddr=:" + m_RemoteAddress.toString() + ":rport=" + m_RemotePort); m_Socket.setReceiveBufferSize(1024); m_Socket.setSendBufferSize(1024); m_ModbusTransport = new ModbusUDPTransport(this); m_Active = true; } if (Modbus.debug) CCLog.info("UDPMasterTerminal::activated"); }
/** * Returns if the host is currently reachable. * * <p>If the host is unreachable, this method will not try again for up to 30 seconds. * * @return If the host is reachable. */ public boolean isAvailable() { if (!UpnpDiscoverer.getDevicePingDetection()) return true; // We are not protected from the remote address suddenly changing. InetAddress remoteAddress = this.remoteAddress; if (remoteAddress != null) { if (System.currentTimeMillis() > timeout) { try { boolean returnValue = remoteAddress.isReachable(UpnpDiscoverer.getDevicePingTimeout()); if (returnValue) { return true; } else { logger.warn("Unable to ping the remote address {}.", remoteAddress.toString()); } } catch (Exception e) { logger.error("Unable to ping the remote address {} => ", remoteAddress.toString(), e); } // Set the timeout for 30 seconds from now. This way when multiple capture devices // on one host are unavailable we don't waste time finding out what we already know // for at least 30 more seconds which should be more than enough time to find a // better capture device or come back to this one and try to use it anyway. timeout = System.currentTimeMillis() + 30000; } return false; } return true; }
/*========================================================================*/ public void init() { /*========================================================================*/ final int port = 9901; initComponents(); try { /*-----------------------------------*/ /* Setup the socket's target address */ /*-----------------------------------*/ // InetAddress address = InetAddress.getByName("localhost");//local InetAddress address = InetAddress.getLocalHost(); // local System.out.println("Local host: " + address.toString()); Socket socket = new Socket(address, port); /*--------------------------------*/ /* Setup the input/output streams */ /*--------------------------------*/ OutputStream os = socket.getOutputStream(); dos = new DataOutputStream(os); InputStream is = socket.getInputStream(); dis = new DataInputStream(is); System.out.println("Setup for all streams complete"); } catch (IOException ioe) { System.out.println("Error connecting"); } }
/** * Activate this <tt>UDPTerminal</tt>. * * @throws Exception if there is a network failure. */ public synchronized void activate() throws Exception { if (!isActive()) { if (Modbus.debug) System.out.println("UDPSlaveTerminal.activate()"); if (m_Socket == null) { if (m_LocalAddress != null && m_LocalPort != -1) { m_Socket = new DatagramSocket(m_LocalPort, m_LocalAddress); } else { m_Socket = new DatagramSocket(); m_LocalPort = m_Socket.getLocalPort(); m_LocalAddress = m_Socket.getLocalAddress(); } } if (Modbus.debug) System.out.println("UDPSlaveTerminal::haveSocket():" + m_Socket.toString()); if (Modbus.debug) System.out.println( "UDPSlaveTerminal::addr=:" + m_LocalAddress.toString() + ":port=" + m_LocalPort); m_Socket.setReceiveBufferSize(1024); m_Socket.setSendBufferSize(1024); m_PacketReceiver = new PacketReceiver(); m_Receiver = new Thread(m_PacketReceiver); m_Receiver.start(); if (Modbus.debug) System.out.println("UDPSlaveTerminal::receiver started()"); m_PacketSender = new PacketSender(); m_Sender = new Thread(m_PacketSender); m_Sender.start(); if (Modbus.debug) System.out.println("UDPSlaveTerminal::sender started()"); m_ModbusTransport = new ModbusUDPTransport(this); if (Modbus.debug) System.out.println("UDPSlaveTerminal::transport created"); m_Active = true; } if (Modbus.debug) System.out.println("UDPSlaveTerminal::activated"); }
/** * {@collect.stats} {@description.open} Constructs a string representation of this * InetSocketAddress. This String is constructed by calling toString() on the InetAddress and * concatenating the port number (with a colon). If the address is unresolved then the part before * the colon will only contain the hostname. {@description.close} * * @return a string representation of this object. */ public String toString() { if (isUnresolved()) { return hostname + ":" + port; } else { return addr.toString() + ":" + port; } }
/** * Converts an InetAddress into an IPv6 address. * * @param inetAddress the InetAddress value to use. It must contain an IPv6 address * @return an IPv6 address * @throws IllegalArgumentException if the argument is invalid */ public static Ip6Address valueOf(InetAddress inetAddress) { byte[] bytes = inetAddress.getAddress(); if (inetAddress instanceof Inet6Address) { return new Ip6Address(bytes); } if ((inetAddress instanceof Inet4Address) || (bytes.length == INET_BYTE_LENGTH)) { final String msg = "Invalid IPv6 version address string: " + inetAddress.toString(); throw new IllegalArgumentException(msg); } // Use the number of bytes as a hint if (bytes.length == INET6_BYTE_LENGTH) { return new Ip6Address(bytes); } final String msg = "Unrecognized IP version address string: " + inetAddress.toString(); throw new IllegalArgumentException(msg); }
private String printable(InetAddress ia) { if (options.showHostName) { return ia.getHostName(); } else { return ia.toString(); } }
/** Publish a request message to the specified multicast group. */ protected void publishRequest(String message) throws IOException, SocketException { groupAddr = InetAddress.getByName(request_group); interfaceAddr = InetAddress.getByName(request_interface_address); /* is it a multicast address? */ if (groupAddr.isMulticastAddress()) { /* open the socket and join the multicast group */ udpSocket = new MulticastSocket(); udpSocket.setNetworkInterface(NetworkInterface.getByInetAddress(interfaceAddr)); udpSocket.setInterface(interfaceAddr); udpSocket.joinGroup(groupAddr); /* Send request packet */ DatagramPacket p = new DatagramPacket(message.getBytes(), message.getBytes().length, groupAddr, 7777); System.out.println("Sending request: " + new String(p.getData(), 0, p.getLength())); udpSocket.send(p); } else { System.err.println("Invalid multicast address: " + groupAddr.toString()); } }
public void Reply_Command(byte ReplyCode) { // Logs.Println("SOCKS 5 - Reply to Client \"" + ReplyName(ReplyCode) + "\""); int port = 0; String DomainName = "0.0.0.0"; InetAddress InetAdd = null; byte[] REPLY = new byte[10]; byte IP[] = new byte[4]; if (Parent.LinuxSocket != null) { InetAdd = Parent.LinuxSocket.getInetAddress(); DomainName = InetAdd.toString(); port = Parent.LinuxSocket.getLocalPort(); } else { IP[0] = 0; IP[1] = 0; IP[2] = 0; IP[3] = 0; port = 0; } REPLY[0] = SOCKS5_Version; REPLY[1] = ReplyCode; // Reply Code; REPLY[2] = 0x00; // Reserved '00' REPLY[3] = 0x01; // DOMAIN NAME Type IP ver.4 REPLY[4] = IP[0]; REPLY[5] = IP[1]; REPLY[6] = IP[2]; REPLY[7] = IP[3]; REPLY[8] = (byte) ((port & 0xFF00) >> 8); // Port High REPLY[9] = (byte) (port & 0x00FF); // Port Low Parent.SendToClient(REPLY); } // Reply_Command()
@Override public void run() { /* 如果由于对端异常退出,所以没有收到offline消息,无法得知其是否在线,为此设心跳线程 */ final long timeOutMinute = 3 * 60; while (isOnLine) { long crentTime = System.currentTimeMillis(); long timeCount = crentTime - udpLastRecvTime; // 时间差 if (timeCount > timeOutMinute * 1000L) { String addrStr = clientAddr.toString(); // if(true == MainManage.getHostIp().equals(addrStr.substring(1))) { // continue; // } MainManage.cleanClient(addrStr); MainManage.print("timeout"); } else if (timeCount > 1 * 60 * 1000L) { // 1 minte MainManage.sendOnLineMsg(this, null); } try { Thread.sleep(60 * 1000L); } catch (InterruptedException e) { e.printStackTrace(); } } }
@Override public String toString() { String ret = "addresses:\n"; for (InetAddress address : addresses) ret += address.toString() + "\n"; ret += "names:\n"; for (String name : names) ret += name + "\n"; return ret; }
public WikiResource(EtxGraph graph) { _topo = Maps.newHashMap(); for (Node node : graph.getNodeList()) { for (InetAddress address : node.getAllIps()) { _topo.put(address.toString(), new WikiRouterItem(node, address)); } } }
public AntidoteConnection(InetAddress addr, int port) throws IOException { log.info("Trying to connect to " + addr.toString() + ":" + port); sock = new Socket(addr, port); sock.setSendBufferSize(1024 * 200); dout = new DataOutputStream(new BufferedOutputStream(sock.getOutputStream(), 1024 * 200)); din = new DataInputStream(new BufferedInputStream(sock.getInputStream(), 1024 * 200)); // log.info("Connected..."); }
/** * @param inetAddr Inet4Address or Inet6Address * @return a string representation of an InetAddress for BPF. */ public static String toBpfString(InetAddress inetAddr) { if (inetAddr == null) { StringBuilder sb = new StringBuilder(); sb.append("inetAddr: ").append(inetAddr); throw new NullPointerException(sb.toString()); } String strAddr = inetAddr.toString(); return strAddr.substring(strAddr.lastIndexOf("/") + 1); }
private void wakeupEthernetAddresses(String address, InetAddress host, int port) throws IllegalEthernetAddressException { try { EthernetAddress ethernetAddress = new EthernetAddress(address); WakeUpUtil.wakeup(ethernetAddress, host, port); } catch (IOException e) { System.err.println( Messages.ERROR_MESSAGES.getFormattedString( "wakeup.io", host.toString(), String.valueOf(port))); } }
/** Sets the local IP address into the variable <i>localIpAddress</i> */ public static void setLocalIpAddress() { localIpAddress = "127.0.0.1"; try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (inetAddress.getHostAddress().toString().contains(":")) continue; if (!PreferenceManager.getDefaultSharedPreferences(getUIContext()) .getBoolean(Settings.PREF_STUN, Settings.DEFAULT_STUN)) { localIpAddress = inetAddress.getHostAddress().toString(); } else { try { String StunServer = PreferenceManager.getDefaultSharedPreferences(getUIContext()) .getString(Settings.PREF_STUN_SERVER, Settings.DEFAULT_STUN_SERVER); int StunServerPort = Integer.valueOf( PreferenceManager.getDefaultSharedPreferences(getUIContext()) .getString( Settings.PREF_STUN_SERVER_PORT, Settings.DEFAULT_STUN_SERVER_PORT)); DiscoveryTest StunDiscover = new DiscoveryTest(inetAddress, StunServer, StunServerPort); // call out to stun server StunDiscover.test(); // System.out.println("Public ip is:" + // StunDiscover.di.getPublicIP().getHostAddress()); localIpAddress = StunDiscover.di.getPublicIP().getHostAddress(); } catch (BindException be) { if (!Sipdroid.release) System.out.println(inetAddress.toString() + ": " + be.getMessage()); } catch (Exception e) { if (!Sipdroid.release) { System.out.println(e.getMessage()); e.printStackTrace(); } } } } } } } catch (Exception ex) { // do nothing } }
/** * Get the primary IP address tied to a network interface (excluding loop-back etc) * * @param networkInterfaceName the name of the network interface to interrogate * @return null if the network interface or address wasn't found. * @throws SocketException in case of a security or network error */ public static final String getIPAddress(String networkInterfaceName) throws SocketException { NetworkInterface networkInterface = NetworkInterface.getByName(networkInterfaceName); Enumeration<InetAddress> ipAddresses = networkInterface.getInetAddresses(); while (ipAddresses.hasMoreElements()) { InetAddress inetAddress = (InetAddress) ipAddresses.nextElement(); if (!inetAddress.isLoopbackAddress() && inetAddress.toString().indexOf(":") < 0) { String hostname = inetAddress.getHostAddress(); return hostname; } } return null; }
@Override public Value convertTo(Type type) { switch (type.getPrimaryType()) { case CONTACT: return this; case STRING: if (isNull()) return ValueString.NULL_STRING; else return new ValueString("(" + name.toString() + ", " + address.toString() + ")"); default: throw new UnsupportedConversionException(getType(), type); } }
public JilterStatus connect(String hostname, InetAddress hostaddr, Properties properties) { rcpts = new ArrayList<String>(); if (hostaddr != null) { host = hostaddr.toString(); } else if (host != null) { host = hostname; } else { host = "localhost"; } logger.debug("jilter connect() {from='" + hostname + "',host='" + host + "'}"); return JilterStatus.SMFIS_CONTINUE; }
public synchronized void addClient(InetAddress ip) { ClientInfo client = this.getClient(ip); if (client == null) { this.clients.add(new ClientInfo(ip)); } else { if (client.isAnAttacker()) { logger.fatal("ATTACK from " + ip.toString() + "!! Attacker added to blacklist"); this.Blacklist.addAddressToBlacklist(ip); } else { client.incrementRequest(); } } }
/** * Determins the IP address of the machine Kettle is running on. * * @return The IP address */ public static final String getIPAddress() throws Exception { Enumeration<NetworkInterface> enumInterfaces = NetworkInterface.getNetworkInterfaces(); while (enumInterfaces.hasMoreElements()) { NetworkInterface nwi = (NetworkInterface) enumInterfaces.nextElement(); Enumeration<InetAddress> ip = nwi.getInetAddresses(); while (ip.hasMoreElements()) { InetAddress in = (InetAddress) ip.nextElement(); if (!in.isLoopbackAddress() && in.toString().indexOf(":") < 0) { return in.getHostAddress(); } } } return "127.0.0.1"; }
/** * Returns an enumeration of inform communities for a given host. * * @param i The address of the host. * @return An enumeration of inform communities for a given host (enumeration of <CODE>String * </CODE>). */ public Enumeration<String> getInformCommunities(InetAddress i) { Vector<String> list = null; if ((list = informDestList.get(i)) != null) { if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp( Level.FINER, SnmpAcl.class.getName(), "getInformCommunities", "[" + i.toString() + "] is in list"); } return list.elements(); } else { list = new Vector<>(); if (SNMP_LOGGER.isLoggable(Level.FINER)) { SNMP_LOGGER.logp( Level.FINER, SnmpAcl.class.getName(), "getInformCommunities", "[" + i.toString() + "] is not in list"); } return list.elements(); } }
/** * Returns a string containing details of this network interface. The exact format is deliberately * unspecified. Callers that require a specific format should build a string themselves, using * this class' accessor methods. */ @Override public String toString() { StringBuilder sb = new StringBuilder(25); sb.append("["); sb.append(name); sb.append("]["); sb.append(interfaceIndex); sb.append("]"); for (InetAddress address : addresses) { sb.append("["); sb.append(address.toString()); sb.append("]"); } return sb.toString(); }
/** @param */ public static void main(String[] para) throws UnknownHostException { InetAddress IP0 = InetAddress.getLocalHost(); String name = IP0.getCanonicalHostName(); byte[] address = IP0.getAddress(); String hostAddress = IP0.getHostAddress(); String ip = IP0.toString(); System.out.println( "CanonicalHostName is : " + name + " hostAddress is:" + hostAddress + " address is:" + address + " IP is:" + ip); }
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("interface " + networkInterface + " :"); if ((flags & NET_LOCALHOST) != 0) { sb.append(" localhost"); } if ((flags & NET_WIFI) != 0) { sb.append(" wifi"); } if ((flags & NET_ETHERNET) != 0) { sb.append(" ethernet"); } sb.append("\n"); for (InetAddress address : addresses) { sb.append(" addr " + address.toString() + "\n"); } return sb.toString(); }
public static InetAddress getFirstNonLoopbackLocalInetAddress() { InetAddress[] addrs = getAllLocalInetAddresses(); if (addrs != null) { for (InetAddress addr : addrs) { if (s_logger.isInfoEnabled()) { s_logger.info( "Check local InetAddress : " + addr.toString() + ", total count :" + addrs.length); } if (!addr.isLoopbackAddress()) { return addr; } } } s_logger.warn( "Unable to determine a non-loopback address, local inet address count :" + addrs.length); return null; }
public String toString() { String ret = ""; ret += "Machine : " + ipLocale.toString() + "\n"; ret += " classe : " + this.getClassIP(); if (this.getClassIP() == 'A' || this.getClassIP() == 'B' || this.getClassIP() == 'C') { ret += ", réseau d'appartenance : "; try { ret += this.getNetwork().toString(); } catch (Exception e) { e.printStackTrace(); } ret += "\n adresse de diffusion : "; try { ret += this.getBroadcast().toString(); } catch (Exception e) { e.printStackTrace(); } } ret += "\n"; return ret; }
/** * Get the string defining the hostname of the system, as taken from the default network adapter * of the system. There is no guarantee that this will be fully qualified, or that it is the * hostname used by external machines to access the server. If we cannot determine the name, then * we return the default hostname, which is defined by {@link #LOCALHOST} * * @return a string name of the host. */ public static String getLocalHostname() { InetAddress address; String hostname; try { address = InetAddress.getLocalHost(); // force a best effort reverse DNS lookup hostname = address.getHostName(); if (hostname == null || hostname.length() == 0) { hostname = address.toString(); } } catch (UnknownHostException noIpAddrException) { // this machine is not on a LAN, or DNS is unhappy // return the default hostname if (log.isDebugEnabled()) { log.debug("Failed to lookup local IP address", noIpAddrException); } hostname = LOCALHOST; } return hostname; }
static String getHostNameNoResolve(InetSocketAddress socketAddress) { if (Xnio.NIO2) { return socketAddress.getHostString(); } else { String hostName; if (socketAddress.isUnresolved()) { hostName = socketAddress.getHostName(); } else { final InetAddress address = socketAddress.getAddress(); final String string = address.toString(); final int slash = string.indexOf('/'); if (slash == -1 || slash == 0) { // unresolved both ways hostName = string.substring(slash + 1); } else { // has a cached host name hostName = string.substring(0, slash); } } return hostName; } }