我记得好像是可以的,以前我好像用
InetAddress ipaddr = InetAddress.getByName("www.sina.com.cn");
String hostname = ipaddr.getHostName();
InetAddress [] ipaddrs = InetAddress.getAllByName(hostname);
就能取到多个地址
InetAddress ipaddr = InetAddress.getByName("www.sina.com.cn");
String hostname = ipaddr.getHostName();
InetAddress [] ipaddrs = InetAddress.getAllByName(hostname);
就能取到多个地址
解决方案 »
- 前辈们,异常捕捉问题请教!
- 为什么说:“如果根据 equals(Object) 方法,两个对象是相等的,那么在两个对象中的每个对象上调用 hashCode 方法都必须生成相同的整数结
- 如何清空APPLET小窗口的内容
- 写一个方法接收一个字符串,完成以下要求然后返回处理后的字符串
- 紧急送分题
- 请教一个swing的问题:jcombobox中,如何获取输入值
- SOS 救救我吧!这个问题困惑了我好几天了。
- 求助!~AIP73135430AIP43496203
- 请问这里有没有搞Java3D的,大家对Java3D有怎么看法?
- 有关swing的问题,请高手回答
- 高手来看了 一个项目问题(聊天室 )
- eclipse 几种版本有什么区别啊?
System.out.println( ipaddrs[i].getHostAddress());
}
String hostname = ipaddr.getHostName();
InetAddress [] ipaddrs = InetAddress.getAllByName(hostname); 上面的代码是不是取到的是通过域名解析得到的IP地址,如果要得本地多个网卡的IP,一定能行么?
我同意你的观点,
继续关注中。一个域名可以被解析到多个IP吗?是轮询的呢,还是并发地把对一域名的服务请求分发到多个不同IP的服务器上?请高手赐教啊。不胜感谢
import java.net.* ;
import java.awt.event.* ;
import javax.swing.* ;
public class GUIIp extends JPanel
{
JTextField texthost ;
JLabel labelip ;
String ipstring ;
JButton displaybutton ;
InetAddress IpAddress = null ;
GUIIp()
{
labelip = new JLabel("ip address") ;
texthost = new JTextField("please enter a host name.", 15) ;
//texthost.selectAll() ;
displaybutton = new JButton("display ip address") ;
setLayout(new GridLayout(0,1)) ;
add(texthost) ;
add(displaybutton) ;
add(labelip) ;
displaybutton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ipstring = texthost.getText().trim() ;
texthost.selectAll() ;
try
{
IpAddress = InetAddress.getByName(ipstring) ; labelip.setText(IpAddress.getHostAddress()) ;
}
catch(UnknownHostException eip)
{
System.out.println(eip.toString()) ;
}
}
}) ;
}
public static void main(String[] args)
{
JFrame frame = new JFrame("Display ip address") ;
frame.addWindowListener(new CloseWindow()) ;
frame.getContentPane().add(new GUIIp()) ;
frame.pack() ;
frame.setVisible(true) ;
}
}
class CloseWindow extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0) ;
}
}