Desidero trovare il nome host in base all'indirizzo IP specificato nel mio programma. E 'possibile ottenerlo, se sì puoi fornire il codice. Grazie.Come ottenere il nome host in base all'indirizzo IP?
6
A
risposta
11
Sì, è possibile.
import java.net.*;
public class HostName
{
public static void main(String args[])
{
InetAddress inetAddress =InetAddress.getByName("127.64.84.2");//get the host Inet using ip
System.out.println ("Host Name: "+ inetAddress.getHostName());//display the host
}
}
4
Qualcosa del genere dovrebbe puntare nella giusta direzione:
import java.net.InetAddress;
import java.net.UnknownHostException;
public class DNSLookup {
public static void main(String args[]) {
try {
InetAddress host;
if (args.length == 0) {
host = InetAddress.getLocalHost();
} else {
host = InetAddress.getByName(args[0]);
}
System.out.println("Host:'" + host.getHostName()
+ "' has address: " + host.getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
0
È possibile utilizzare getHostName()
metodo InetAddress
di classe.
0
Provate questo fuori ....
System.out.println(InetAddress.getByName("IP_ADDR").getHostName());
0
Hey io m utilizzando metodi di cui sopra bt il metodo getHostName() non restituisce il nome host del dato ip.
codice vedi:
try {
// This is ip of tutorialspoint.com
InetAddress addr2 = InetAddress.getByName("127.64.84.2");
op.setText("Host name is: "+addr2.getHostName());
}
catch (UnknownHostException e3) {
op.setText("Error: Host not found" + e3);
}
0
import java.net.*;
public class GetHostNameFromIPAddress {
public static void main(String[] args) {
try {
InetAddress inetAddr = InetAddress.getByName("163.53.76.55");
// Get the host name
String hostname = inetAddr.getHostName();
// Get canonical host name
String canonicalHostname = inetAddr.getCanonicalHostName();
System.out.println("Hostname: " + hostname);
System.out.println("Canonical Hostname: " + canonicalHostname);
}
catch (UnknownHostException e) {
System.out.println("Host not found: " + e.getMessage());
}
}
}
Problemi correlati
- 1. PHP Ottieni IP in base al nome host
- 2. Ottieni nome host dall'indirizzo IP
- 3. Indirizzo IP a nome host in Java?
- 4. Indirizzo IPv6 in base al nome host
- 5. Risoluzione indirizzo IP di un nome host
- 6. Impossibile determinare l'indirizzo IP dal nome host
- 7. Risolvi IP su Nome host usando PHP
- 8. condizionale elisp in base al nome host
- 9. Nome host/IP non corrisponde al nome alternativo del certificato
- 10. Come risolvere il nome host dall'IP locale in C# .NET?
- 11. Come ottenere i dati client (IP, nome host) dal trasporto websocket in phoenix?
- 12. .htaccess Imposta il valore PHP in base al nome host
- 13. IP host Wordpress modificato
- 14. Linux - modificare il nome host nella CLI
- 15. Come ottenere il nome host nel modello freemarker?
- 16. Ottieni il nome host senza utilizzare HttpRequest
- 17. conversione di un indirizzo IP nel nome host
- 18. Come convalidare il nome host (può essere IP) e il numero di porta (CString)
- 19. Come ottenere l'indirizzo IP dal nome di dominio in Java?
- 20. Come impostare il nome host usando php curl per un ip specifico
- 21. In C#, come posso risolvere l'indirizzo IP di un host?
- 22. Il file host può reindirizzare un indirizzo IP?
- 23. Come verificare il nome host del server
- 24. Debugger oggetto Facebook - Impossibile risolvere il nome host in un indirizzo IP valido
- 25. Qual è il modo migliore per ottenere il nome del computer in remoto in base a un indirizzo IP?
- 26. come ottenere il nome della classe derivata dalla classe base
- 27. Convalida IPv4, IPv6 e nome host
- 28. come reindirizzare il dominio in base all'indirizzo IP del paese
- 29. Come ottenere l'indirizzo IP?
- 30. Interrogare i record di servizio DNS per trovare il nome host e TCP/IP