Hello All

Is it possible to check the ip address of a particular web site?

If yes what will be the code?

Recommended Answers

All 2 Replies

C++:

http://www.daniweb.com/software-development/cpp/threads/134017

C != C++

Linux, IPv4:

#include <netdb.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <stdio.h>

int main(int argc, char** argv)
{
	hostent * record = NULL;
	in_addr* address = NULL;
	char* ip_address = NULL;
	
	if(argc != 2)
	{
		printf("usage: %s <hostname>\n", argv[0], argv[1]);
		return 1;
	}
		
	record = gethostbyname(argv[1]);
	if(record == NULL)
	{
		printf("%s is unavailable\n", argv[1]);
		return 1;
	}
	
	address = (in_addr*)record->h_addr;
	ip_address = inet_ntoa(*address);
	
	printf("%s (%s)\n", argv[1], ip_address);
	
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.