import java.net.*;
public class GetSelfIp{
 public GetSelfIp(){
}
public static void main(String[] args){
  InetAddress host = InetAddress.getByName(null);  // 
 .........
}

这是取本机IP地址

解决方案 »

  1.   

    socket.getInetAddress() 
    socket.getPort()
      

  2.   

    那怎么随机产生流量和获取协议啊?
    比如产生流量:232 495
    协议:HTTP/1.0
    多谢各位!
      

  3.   

    InetAddress.getByName(String pcname)
      

  4.   

    取得地址的方式有很多,在InetAddress中有以下三种:
    getByName(String hostName)
    getAllByName(String hostName)
    getLocalHost()*********在DatagramPacket中:
    getAddress()
    getlocalAddress()*********在Socket中:
    getInetAddress()
    getLocalAddress()*********在SocketImpl中:
    getInetAddress()*********在ServerSocket中:
    getInetAddress()