获取自己的IP地址不需要socket编程,下面是用Java写的。
import java.net.InetAddress;
public class IpDemo {
public static void main(String[] args)throws Exception{
InetAddress[] addr = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
for(InetAddress ia : addr){
System.out.println(ia.getHostAddress());
}
}
}
关于java socket编程的,可以参考
http://blog.csdn.net/leon_7mx/archive/2011/03/19/6261282.aspx
gethostbyname()
就可以,具体查下MSDN手册就知道了。