Hi!
I was wondering if there's a way to view the IP address of a certain site through Command Prompt. Even better, maybe there's a way to access it through a c++ or java program!
thanx.
Hi!
I was wondering if there's a way to view the IP address of a certain site through Command Prompt. Even better, maybe there's a way to access it through a c++ or java program!
thanx.
Quick practical add-on to the existing replies: ’s ping pointer and ’s nslookup note show how to get an IP at the command line, and ’s Java examples are on the right track. For a reliable programmatic solution, use the language’s DNS resolver or a DNS library instead of parsing ping/nslookup output — parsing is brittle and will break across OSes, locales, or tool versions.
In Java, prefer resolving all records (not just the first) when a hostname may have multiple A/AAAA entries, and handle the JVM’s DNS caching and lookup exceptions appropriately. When servlet code is involved, remember that the servlet request methods return client addresses (not the DNS resolution of an arbitrary domain). For fine-grained DNS control (timeouts, record types, explicit servers), use a DNS client library rather than the built-in resolver.
A compact, cross-platform C/C++ approach uses getaddrinfo and getnameinfo (call WSAStartup/WSACleanup on Windows). The core loop looks like:
/* resolve 'hostname' to numeric IPs */
struct addrinfo hints = {};
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo *res = nullptr;
if (getaddrinfo(hostname, nullptr, &hints, &res) == 0) {
for (struct addrinfo *p = res; p; p = p->ai_next) {
char ip[NI_MAXHOST];
if (getnameinfo(p->ai_addr, p->ai_addrlen, ip, sizeof(ip), nullptr, 0, NI_NUMERICHOST) == 0)
std::cout << ip << "\n";
}
freeaddrinfo(res);
} Notes and caveats: hosts often have multiple A/AAAA records (CDNs, load balancers), DNS responses depend on the resolver used, and results can change with TTLs or client location. For accurate, repeatable answers use DNS APIs or libraries and consider querying a specific DNS server rather than relying on a single local tool output.
Jump to Post— Catweazle 140
Jump to Post— server_crash 64Even better, maybe there's a way to access it through a c++ or java program!
thanx.
You can access a site through java without knowing the IP Address. look up the java.net.*; package.
Even better, maybe there's a way to access it through a c++ or java program!
thanx.
You can access a site through java without knowing the IP Address. look up the java.net.*; package.
server_crash, thanx but i already know that. I wanted 2 make a program that tells u the ip address of the inputted domain name.
thanx anyway.
server_crash, thanx but i already know that. I wanted 2 make a program that tells u the ip address of the inputted domain name.
thanx anyway.
The ping command referenced in Catweazle's link will return the IP, although by default it will query a site 4 times, echo a response for every query, and then barf summary statistics on top of that. You can limit the query count with the "-n" switch, but it will still return the stats as well.
You might also check out the "nslookup" command.
thanx. one more question. is there a way to return the ip address to a java/c++ program?
thanx. one more question. is there a way to return the ip address to a java/c++ program?
This is how you can grab the client ip address:
InetAddress thisIp =
InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress()); Remember to include that in a try catch clause, as that code could potentially cause an exception.
Also, writting a simple servlet would be easier:
String IP = req.getRemoteAddr(); req is an HTTPServletRequest Object.
Sorry, you might want to get it by the hostname:
java.net.InetAddress inetAdd =
java.net.InetAddress.getByName("www.ibm.com");
System.out.println ("IP Address is : " + inetAdd.getHostAddress()); We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.