根据获取的主机名显示ip地址
2013-01-01 14:51
363 查看
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.net.*; public class IPTest extends JFrame implements ActionListener { JLabel lb=new JLabel("显示IP地址"); JTextField text=new JTextField(12); JButton btn=new JButton("单击本按钮,显示IP地址"); IPTest() { JFrame frame=new JFrame("IP显示"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BorderLayout border=new BorderLayout(); frame.setLayout(border); frame.add(lb,BorderLayout.NORTH); frame.add(text,BorderLayout.CENTER); frame.add(btn,BorderLayout.SOUTH); btn.addActionListener(this); frame.setLocation(new Point(300, 300)); frame.setSize(300,200); frame.validate(); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { try { InetAddress local=InetAddress.getByName(text.getText().trim()); lb.setText(local.getHostAddress().toString()); } catch(Exception ex) { JOptionPane.showMessageDialog(this, "无法识别的输入的主机名","警告对话框",JOptionPane.WARNING_MESSAGE); } } public static void main(String[] args) { new IPTest(); } }
相关文章推荐
- 根据ip地址获取主机名称
- 根据主机名获取PC的IP地址
- 根据主机名获取PC的IP地址
- 使用VMware VSphere WebService SDK进行开发 (五)——根据虚拟机的名称获取对应主机的IP地址
- 使用VMware VSphere WebService SDK进行开发 (五)——根据虚拟机的名称获取对应主机的IP地址
- unix网络编程之根据主机名(hostname)或网卡名获取IP地址(三种方法)
- 根据主机名获取IP地址
- Linux中根据主机名获取其在局域网中的IP地址
- 根据主机名获取IP地址
- [Win32]根据主机名、域名、IP字符串获取IP地址
- java根据ip地址获取详细地域信息
- PHP根据IP地址获取所在城市
- 获取游戏设计的分辨率与真实设备的比例,并根据值来剪切显示区域
- 根据IP地址获取详细的地域信息
- Python语言实现获取主机名根据端口杀死进程
- 根据IP地址获取所在城市
- gethostbyname() -- 用域名或主机名获取IP地址
- 根据ip地址和掩码求网络地址,主机号,广播号和主机最大数。。
- 批量获取主机名对应的ip地址
- JS实现密码框根据焦点的获取与失去控制文字的消失与显示效果