从SocketAddress获取IP
//package com.nowjava;/**来自 时代Java - nowjava.com**/ import java.net.SocketAddress; public class Main { public static String getIP(SocketAddress socketAddress) { if (socketAddress == null) { throw new NullPointerException("remoteAddres is null"); } String address = socketAddress.toString(); return address.substring(1, address.indexOf(':')); } }