请问JAVA程序中如何实现根据IP地址,获得域名,也就是所说的域名反向解析 请问JAVA程序中如何实现根据IP地址,获得域名,也就是所说的域名反向解析最近的项目中用用到这块,涉及域名和IP的管理和信息安全的内容请知道思路的高手指教,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 java.net.InetAddress ia = InetAddress.getByName("192.168.100.100");ia.getHostName(); 反向解析首先要求被解析的机器的DNS支持,我也只理解这么多了byte[] b = {(byte)202, (byte)119, (byte)24, (byte)35}; InetAddress addr = InetAddress.getByAddress(b); addr.getHostName() ia.getHostName();这个方法获取不到域名我尝试用nslookup查询到了ip域名对应关系,但用这个方法出不来 你试试我3楼的方法,用byte转一下 public class Test090518 { public static void main(String args[]){ try { String name = Test090518.getHostNameByNbtstat("192.168.12.12"); System.out.println("name="+name); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }// 得到遠程IP的機器名 public static String getHostNameByNbtstat(String clientIP){ String s = ""; String sb = clientIP.trim().substring(0, 3); //System.out.println("clientIP="+clientIP+"\t"+"截取字符串為:"+sb); if(sb.equals("127")){ //System.out.println("是127.0.0.1"); s = getHostName(); }else{ //System.out.println("不是本地ip"); try { String s1 = "nbtstat -a "+clientIP; Process process = Runtime.getRuntime().exec(s1); BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(process.getInputStream())); String nextLine; int y = 0; int x = 0; for (String line = bufferedreader.readLine(); line != null; line = nextLine) { nextLine = bufferedreader.readLine(); //System.out.println("y= "+y+" nextLine="+nextLine); if(y==13){ //System.out.println("此行:-----------------"); //System.out.println(nextLine.indexOf("<00>")+"--------"); s = (nextLine.substring(0, (nextLine.indexOf("<00>")))).toLowerCase();//截取字符串 } y++; } bufferedreader.close(); process.waitFor(); }catch(Exception exception) { s = ""; } } return s.trim(); }// 得到本地IP的機器名 public static String getHostName() { String s = ""; try { String s1 = "ipconfig /all"; Process process = Runtime.getRuntime().exec(s1); BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(process.getInputStream())); String nextLine; for (String line = bufferedreader.readLine(); line != null; line = nextLine) { nextLine = bufferedreader.readLine(); if (line.indexOf("Host Name") <= 0) { continue; } int i = line.indexOf("Host Name") + 36; s = line.substring(i); break; } bufferedreader.close(); process.waitFor(); } catch (Exception exception) { s = ""; } return s.trim(); }}百度的202.108.22.5被喀嚓掉了 試其他的 我想知道的是域名-》ipjava做的动态域名解析,哪位高手做过,求指导 struts2.0 标签<s:iterator/>问题 项目管理 jxl导出excel并上传到ftp服务器 hibernate查询问题 用Tomcat调试jsp程序出现如下:“ userName cannot be resolved” 是怎么回事,请高手帮帮忙阿,急 高人指点如何在Struts中备份mysql数据库 刚做一项目,不知该怎么办! servletoutputstream为xml格式的流如何处理? Hibernate的运行问题 关于电子商务网站多语种数据库设计的问题 spring action 参数 hibernate报错unexpected token: mo near lin
ia.getHostName();
byte[] b = {(byte)202, (byte)119, (byte)24, (byte)35};
InetAddress addr = InetAddress.getByAddress(b);
addr.getHostName()
这个方法获取不到域名
我尝试用nslookup查询到了ip域名对应关系,但用这个方法出不来
public class Test090518 {
public static void main(String args[]){
try {
String name = Test090518.getHostNameByNbtstat("192.168.12.12");
System.out.println("name="+name);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 得到遠程IP的機器名
public static String getHostNameByNbtstat(String clientIP){
String s = "";
String sb = clientIP.trim().substring(0, 3);
//System.out.println("clientIP="+clientIP+"\t"+"截取字符串為:"+sb);
if(sb.equals("127")){
//System.out.println("是127.0.0.1");
s = getHostName();
}else{
//System.out.println("不是本地ip");
try {
String s1 = "nbtstat -a "+clientIP;
Process process = Runtime.getRuntime().exec(s1);
BufferedReader bufferedreader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String nextLine;
int y = 0;
int x = 0;
for (String line = bufferedreader.readLine(); line != null; line = nextLine) {
nextLine = bufferedreader.readLine();
//System.out.println("y= "+y+" nextLine="+nextLine);
if(y==13){
//System.out.println("此行:-----------------");
//System.out.println(nextLine.indexOf("<00>")+"--------");
s = (nextLine.substring(0, (nextLine.indexOf("<00>")))).toLowerCase();//截取字符串
}
y++;
}
bufferedreader.close();
process.waitFor();
}catch(Exception exception) {
s = "";
}
}
return s.trim();
}
// 得到本地IP的機器名
public static String getHostName() {
String s = "";
try {
String s1 = "ipconfig /all";
Process process = Runtime.getRuntime().exec(s1);
BufferedReader bufferedreader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String nextLine;
for (String line = bufferedreader.readLine(); line != null; line = nextLine) {
nextLine = bufferedreader.readLine();
if (line.indexOf("Host Name") <= 0) {
continue;
}
int i = line.indexOf("Host Name") + 36;
s = line.substring(i);
break;
}
bufferedreader.close();
process.waitFor();
} catch (Exception exception) {
s = "";
}
return s.trim();
}
}
百度的202.108.22.5被喀嚓掉了 試其他的