Ejemplo n.º 1
0
const char *whichwhois(const char *s)
{
    unsigned long ip;
    unsigned int i;

    /* IPv6 address */
    if (strchr(s, ':')) {
	if (strncmp(s, "2001:",  5) == 0) {
	    unsigned long v6net = strtol(s + 5, NULL, 16);
	    v6net = v6net & 0xfe00;	/* we care about the first 7 bits */
	    for (i = 0; ip6_assign[i].serv; i++)
		if (v6net == ip6_assign[i].net)
		    return ip6_assign[i].serv;
	    return "\x06";			/* unknown allocation */
	} else if (strncasecmp(s, "3ffe:", 5) == 0)
	    return "whois.6bone.net";
	/* RPSL hierarchical object like AS8627:fltr-TRANSIT-OUT */
	else if (strncasecmp(s, "as", 2) == 0 && isasciidigit(s[2]))
	    return whereas(atoi(s + 2));
	else
	    return "\x05";
    }

    /* email address */
    if (strchr(s, '@'))
	return "\x05";

    /* no dot and no hyphen means it's a NSI NIC handle or ASN (?) */
    if (!strpbrk(s, ".-")) {
	const char *p;

	for (p = s; *p; p++);			/* go to the end of s */
	if (strncasecmp(s, "as", 2) == 0 &&	/* it's an AS */
		(isasciidigit(s[2]) || s[2] == ' '))
	    return whereas(atoi(s + 2));
	else if (strncasecmp(p - 2, "jp", 2) == 0) /* JP NIC handle */
	    return "whois.nic.ad.jp";
	if (*s == '!')	/* NSI NIC handle */
	    return "whois.networksolutions.com";
	else
	    return "\x05";	/* probably a unknown kind of nic handle */
    }

    /* smells like an IP? */
    if ((ip = myinet_aton(s))) {
	for (i = 0; ip_assign[i].serv; i++)
	    if ((ip & ip_assign[i].mask) == ip_assign[i].net)
		return ip_assign[i].serv;
	return "\x05";			/* not in the unicast IPv4 space */
    }

    /* check the TLDs list */
    for (i = 0; tld_serv[i]; i += 2)
	if (domcmp(s, tld_serv[i]))
	    return tld_serv[i + 1];

    /* no dot but hyphen */
    if (!strchr(s, '.')) {
	/* search for strings at the start of the word */
	for (i = 0; nic_handles[i]; i += 2)
	    if (strncasecmp(s, nic_handles[i], strlen(nic_handles[i])) == 0)
		return nic_handles[i + 1];
	/* it's probably a network name */
	return "";
    }

    /* has dot and maybe a hyphen and it's not in tld_serv[], WTF is it? */
    /* either a TLD or a NIC handle we don't know about yet */
    return "\x05";
}
Ejemplo n.º 2
0
const char *
whichwhois (const char *s)
{
  unsigned long ip;
  unsigned int i;

  /* -v or -t has been used */
  if (*s == '\0')
    return "whois.ripe.net";

  /* IPv6 address */
  if (strchr (s, ':'))
    {
      if (strncasecmp (s, "2001:2", 6) == 0)	/* XXX ugly hack! */
	return "whois.apnic.net";
      if (strncasecmp (s, "2001:4", 6) == 0)
	return "whois.arin.net";
      if (strncasecmp (s, "2001:6", 6) == 0)
	return "whois.ripe.net";
      /* if (strncasecmp(s, "3ffe", 4) == 0) */
      return "whois.6bone.net";
    }

  /* email address */
  if (strchr (s, '@'))
    return "";

  /* no dot and no hyphen means it's a NSI NIC handle or ASN (?) */
  if (!strpbrk (s, ".-"))
    {
      const char *p;

      for (p = s; *p != '\0'; p++);	/* go to the end of s */
      if (strncasecmp (s, "as", 2) == 0 &&	/* it's an AS */
	  ((s[2] >= '0' && s[2] <= '9') || s[2] == ' '))
	return whereas (atoi (s + 2), as_assign);
      else if (strncasecmp (p - 2, "jp", 2) == 0)	/* JP NIC handle */
	return "whois.nic.ad.jp";
      if (*p == '!')		/* NSI NIC handle */
	return "whois.networksolutions.com";
      else			/* it's a NSI NIC handle or something we don't know about */
	return "";
    }

  /* smells like an IP? */
  if ((ip = myinet_aton (s)))
    {
      for (i = 0; ip_assign[i].serv; i++)
	if ((ip & ip_assign[i].mask) == ip_assign[i].net)
	  return ip_assign[i].serv;
      if (verb)
	puts (_("I don't know where this IP has been delegated.\n"
		"I'll try ARIN and hope for the best..."));
      return "whois.arin.net";
    }

  /* check TLD list */
  for (i = 0; tld_serv[i]; i += 2)
    if (domcmp (s, tld_serv[i]))
      return tld_serv[i + 1];

  /* no dot but hyphen */
  if (!strchr (s, '.'))
    {
      /* search for strings at the start of the word */
      for (i = 0; nic_handles[i]; i += 2)
	if (strncasecmp (s, nic_handles[i], strlen (nic_handles[i])) == 0)
	  return nic_handles[i + 1];
      if (verb)
	puts (_("I guess it's a netblock name but I don't know where to"
		" look it up."));
      return "whois.arin.net";
    }

  /* has dot and hypen and it's not in tld_serv[], WTF is it? */
  if (verb)
    puts (_("I guess it's a domain but I don't know where to look it"
	    " up."));
  return "";
}