Here you can find the source of getIpAddress(SocketAddress sa)
public static String getIpAddress(SocketAddress sa)
//package com.java2s; //License from project: Open Source License import java.net.SocketAddress; public class Main { public static String getIpAddress(SocketAddress sa) { String ip = sa.toString(); if (ip == null) return ""; if (ip.startsWith("/")) ip = ip.substring(1);//from w ww. j a v a2s .co m int i = ip.indexOf(":"); if (i > 0) ip = ip.substring(0, i); return ip; } }