黑马程序员技术交流社区
标题:
【已解决】我制作的一个有UI的小型域名IP查询器,有点疑
[打印本页]
作者:
刘芮铭
时间:
2012-8-27 20:14
标题:
【已解决】我制作的一个有UI的小型域名IP查询器,有点疑
本帖最后由 刘芮铭 于 2012-8-28 17:55 编辑
package myiphunter;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class GetAllIP
{
private Frame f;
private TextField tf;
private Button but;
private TextArea ta;
GetAllIP()
{
init();
}
public void init()
{
f = new Frame("迷你IP地址获取器 V.1.2.3.0版本");
f.setBounds(300,100,600,500);
f.setLayout(new FlowLayout());
tf = new TextField(60);
but = new Button("获取当前地址所有IP列表");
ta = new TextArea(25,70);
f.add(tf);
f.add(but);
f.add(ta);
myEvent();
f.setVisible(true);
}
private void myEvent()
{
tf.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
getIP();
}
});
but.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
getIP();
}
});
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
private void getIP()
{
String hostName = tf.getText();
InetAddress[] ias;
try
{
ias = InetAddress.getAllByName(hostName);
if(hostName!=null)
{
ta.setText("");
ta.append("["+hostName+"]: "+"所有IP地址列表如下:"+"\r\n");
for(InetAddress iad : ias)
{
ta.append(iad+"\r\n");
}
}
}
catch (Exception e)
{
}
}
}
class IPDemo
{
public static void main(String[] args) throws UnknownHostException
{
new GetAllIP();
}
}
复制代码
运行起来还是比较正常的,比如输入这样完整的域名:
www.baidu.com
是可以正常获取IP的
而
http://www.baidu.com/index.php?tn=98012088_3_dg
这样的地址,就获取不到IP,请问怎么样可以解决呢?如下图:
2.jpg
(19.14 KB, 下载次数: 58)
下载附件
2012-8-27 20:12 上传
1.jpg
(21.1 KB, 下载次数: 65)
下载附件
2012-8-27 20:12 上传
作者:
刘芮铭
时间:
2012-8-27 22:24
怎么没人回答啊。。。。。求大侠
作者:
唐见
时间:
2012-8-27 22:28
本帖最后由 唐见 于 2012-8-28 20:10 编辑
在程序中将http://www.baidu.com/index.php?tn=98012088_3_dg中/index及后面的过滤掉在获取所得ip地址看下
作者:
杨卓儒
时间:
2012-8-28 17:53
把com后面的都切掉
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2