Example #1
0
int main( int argc , char *argv[])
{
    unsigned char hostname[100];
 
    //Get the DNS servers from the resolv.conf file
    get_dns_servers();
     
    //Get the hostname from the terminal
    printf("Enter Hostname to Lookup : ");
    scanf("%s" , hostname);
     
    //Now get the ip of this hostname , A record
    ngethostbyname(hostname , T_A);
 
    return 0;
}
Example #2
0
/* Create an internet connection to HOSTNAME on PORT.  The created
   socket will be stored to *SOCK.  */
uerr_t
make_connection (int *sock, char *hostname, unsigned short port)
{
  struct sockaddr_in sock_name;
  /* struct hostent *hptr; */

  /* Get internet address of the host.  We can do it either by calling
     ngethostbyname, or by calling store_hostaddress, from host.c.
     storehostaddress is better since it caches calls to
     gethostbyname.  */
#if 1
  if (!store_hostaddress ((unsigned char *)&sock_name.sin_addr, hostname))
    return HOSTERR;
#else  /* never */
  if (!(hptr = ngethostbyname (hostname)))
    return HOSTERR;
  /* Copy the address of the host to socket description.  */
  memcpy (&sock_name.sin_addr, hptr->h_addr, hptr->h_length);
#endif /* never */

  /* Set port and protocol */
  sock_name.sin_family = AF_INET;
  sock_name.sin_port = htons (port);

  /* Make an internet socket, stream type.  */
  if ((*sock = socket (AF_INET, SOCK_STREAM, 0)) == -1)
    return CONSOCKERR;

  if (opt.bind_address != NULL)
    {
      /* Bind the client side to the requested address. */
      if (bind (*sock, (struct sockaddr *) opt.bind_address,
		sizeof (*opt.bind_address)))
	return CONSOCKERR;
    }

  /* Connect the socket to the remote host.  */
  if (connect (*sock, (struct sockaddr *) &sock_name, sizeof (sock_name)))
    {
      if (errno == ECONNREFUSED)
	return CONREFUSED;
      else
	return CONERROR;
    }
  DEBUGP (("Created fd %d.\n", *sock));
  return NOCONERROR;
}
Example #3
0
int main( int argc , char *argv[]) {
    
	unsigned char hostname[100];

    // Initialize the DNS Server list from http://www.internic.net/zones/named.root
    get_dns_servers();  

	// Get hostname from user
	printf("\nEnter Hostname to lookup: ");
	scanf("%s" , hostname);

    while(!done) {
	    // Get the IP of this hostname until answer records are received
	    ngethostbyname(hostname , T_A);
    }
	return 0;
}
Example #4
0
int main( int argc , char *argv[])
{
	char hostname[100];

	if ( argc >= 3 ) sprintf(hostname,argv[2]); else
	sprintf(hostname,"www.microsoft.com");

	if ( argc >=5 ) timeout=atoi(argv[4]);

	if ( argc >=4 ) port=atoi(argv[3]);

	//Get the DNS servers from the resolv.conf file
        if ( argc == 1 )
	  get_dns_servers();
	else
	  strcpy(dns_servers[0] , argv[1]);
          
	//Get the hostname from the terminal
	//printf("Enter Hostname to Lookup : ");
	//scanf("%s" , hostname);
	//Now get the ip of this hostname , A record
	return ngethostbyname(hostname , T_A);

}
Example #5
0
//check if any record is at blacklist
void check_blacklisted(int records, int pos, string name)
{
    string flag="1";
    string forcheck[records];
    string hostname, reversename;
    int x,k;
    count=0;

    for(k=0; k<records; k++) {
        if(!strcmp(strs[k][12],flag)) {
            for(i=k; i<records; i++)
            {
                for(j=0; j<count; j++)
                {
                    if(!strcmp(strs[k][pos],forcheck[j])) {
                        break;
                    }
                }
                if(j==count)
                {
                    strcpy(forcheck[count],strs[i][pos]);
                    count++;
                }
            }
        }

    }


    for(x=0; x<count; x++)
    {
        printf("###################################################");

        strcpy(reversename,"");
        printf("\nChecking... %24s", forcheck[x]);
        get_dns_servers();	//Get the DNS servers from the resolv.conf file
        strcpy(hostname,forcheck[x]);//for check 240.10.160.1.zen.spamhaus.org
        char separator='.';
        char*p=strtok(hostname,".");
        string namehost[100];
        int fld=0;
        while(p)
        {
            strcpy(namehost[fld],p);
            fld++;
            p=strtok('\0',".");
        }

        //int part=fld;
        strcpy(reversename, namehost[fld]);
        for(i=fld; i>0; i--)
        {
            strcat(reversename, namehost[i-1]);
            if(i!=0)
                strcat(reversename, ".");
        }
        strcat(reversename, "zen.spamhaus.org"); //strcat(reversename, "blacklist.domain.tld");

        printf("\nReversed for check: %s\n", reversename);
        ngethostbyname(reversename, T_A);//Now get the ip of this hostname , A record

    }


}