導航:首頁 > IDC知識 > javaip獲取域名

javaip獲取域名

發布時間:2020-11-28 05:25:00

1、如何用java用用戶數據包協議獲取域名ip地址?

比較困難,現在域名伺服器都能夠根據你的ip,給你返回最快的ip,所以不會多次訪問給出不同的ip。

2、java IP反查域名,我隨意輸入IP,能得到此IP下所有的域名,例子,思路,資料,什麼都要

這個要看操作系統的,不同命令行實現。
Java調命令行的許多了,百度出去一堆回來,故不詳述。

如下:
如果是Linux,則要用到一些arp指令,比如whois之類的。
如果是Windows,則要用到tracert之類的追蹤指令。

3、獲取IP地址的java代碼,在哪裡輸入域名,用的eclipse

根據參數的,不能在控制台輸入

在選中部分那裡輸入域名

4、java如何獲取根域名

1.得到當前工程的根路徑,代碼如下
String path = request.getContextPath();

2.得到登錄的計算機域名,如果沒有域名就得到IP

request.getRemoteHost();

3.得到登錄計算機的IP
request.getRemoteAddr();

5、java通過域名獲取IP地址

public String getIP(String name){
InetAddress address = null;
try {
address = InetAddress.getByName(name);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("獲取失敗");
}
return address.getHostAddress().toString();
}

6、Java怎麼判斷URL是域名格式還是IP加埠格式?

簡單的辦法是判斷host格式,復雜的但穩妥的辦法是當做域名處理,域名解析,如果解析出來的IP和域名字元串相等,那就是說當做的域名,其實是ip。

try {
URL url=new URL("http://www.sina.com.cn");
String host=url.getHost();
InetAddress address = null;
address = InetAddress.getByName(host);
if(host.equalsIgnoreCase(address.getHostAddress()))
System.out.println("ip");
else
System.out.println("domain");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

7、java 怎麼根據IP地址獲取主機

//看看這個代碼如何。
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;
import java.util.Set;


public class TestSystemProperties {

public static void main(String [] args){
InetAddress netAddress = getInetAddress();
System.out.println("host ip:" + getHostIp(netAddress));
System.out.println("host name:" + getHostName(netAddress));
Properties properties = System.getProperties();
Set<String> set = properties.stringPropertyNames(); //獲取java虛擬機和系統的信息。
for(String name : set){
System.out.println(name + ":" + properties.getProperty(name));
}
}

public static InetAddress getInetAddress(){

    try{
     return InetAddress.getLocalHost();
    }catch(UnknownHostException e){
System.out.println("unknown host!");
}
    return null;

}

public static String getHostIp(InetAddress netAddress){
if(null == netAddress){
return null;
}
String ip = netAddress.getHostAddress(); //get the ip address
return ip;
}

public static String getHostName(InetAddress netAddress){
if(null == netAddress){
return null;
}
String name = netAddress.getHostName(); //get the host address
return name;
}

}

這個代碼簡單明了,就是調用現成的InetAddress類

8、java通過域名怎麼獲取本機ip

import java.net.InetAddress;
import java.net.UnknownHostException;
public class NsLookup {
static public void main(String[] args) {
try {
System.out.println("try");
InetAddress address = InetAddress.getByName(args[0]);
System.out.println(args[0]+" : "+address.getHostAddress());

}catch(UnknownHostException uhe) {
System.out.println("catch");
System.err.println("Unable to find: "+args[0]);

}
}

}

與javaip獲取域名相關的知識