Chinaunix首页 | 论坛 | 博客

acc

  • 博客访问: 792505
  • 博文数量: 170
  • 博客积分: 7011
  • 博客等级: 少将
  • 技术积分: 1660
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-31 12:02
文章分类

全部博文(170)

文章存档

2014年(7)

2010年(2)

2009年(62)

2008年(25)

2007年(67)

2006年(7)

我的朋友

分类: Java

2006-08-22 00:18:50

不足之处,各位指点.偶在学习中.............
import java.net.*;
import java.io.*;
public class _0001GetIP
{
InetAddress myIPaddress=null;
InetAddress myServer=null;
String s;
BufferedReader bin;
public static void main( String args[])
{
_0001GetIP mytool=new _0001GetIP();
System.out.println("Your host IP is: " + mytool.getMyIP());
System.out.println();
System.out.println("The Server IP is :" +mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try
{
 myIPaddress=InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
 System.out.println("error occured");}
    return myIPaddress;
}
//取得 的IP
public InetAddress getServerIP()
{
 try
 {
  System.out.print("Enter your DNS:");
    InputStreamReader in=new InputStreamReader(System.in);
    BufferedReader bin=new BufferedReader(in);
  s=bin.readLine();
  myServer=InetAddress.getByName(s);
 }
catch (Exception e)
  {
   e.printStackTrace();
  }
return myServer;
}
}
 
阅读(1330) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~