Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "RBL.h"
- //bl.spamcop.net, recent.spam.dnsbl.sorbs.net zombie.dnsbl.sorbs.net
- bool RBL::check(const char* ip)
- {
- if(!ip || 0 == strlen(ip) || INADDR_NONE == inet_addr(ip))
- return false;
- // Get the RBL info
- RBLINFO* rbl = NULL;
- get_RBL_info(rbl);
- // Build the lookup domain
- std::string lookupDomain;
- build_request_domain(ip, rbl->domain, lookupDomain);
- // Do the lookup
- IP4_ADDRESS resultIP = 0;
- if(!lookup(lookupDomain.c_str(), &resultIP))
- return false;
- // Iterate over types to find if one matches
- for(unsigned int i = 0; i < rbl->numberOfTypes; i++)
- {
- if(rbl->types[i].ip == resultIP)
- {
- printf("Bad! You're a %s\n", rbl->types[i].type);
- return true;
- }
- }
- return false;
- }
- void RBL::get_RBL_info(RBLINFO* info)
- {
- IP2TYPE spamhausTypes[] = {
- {"ROSKO and known Spammers", inet_addr("127.0.0.2")},
- {"ROSKO and known Spammers", inet_addr("127.0.0.3")},
- {"3rd party exploits", inet_addr("127.0.0.4")},
- {"3rd party exploits", inet_addr("127.0.0.5")},
- {"3rd party exploits", inet_addr("127.0.0.6")},
- {"3rd party exploits", inet_addr("127.0.0.7")},
- {"Dynamic IP", inet_addr("127.0.0.10")},
- {"Dynamic IP", inet_addr("127.0.0.11")},
- };
- static RBLINFO spamhaus = {spamhausTypes, _countof(spamhausTypes), "zen.spamhaus.org"};
- info = &spamhaus;
- }
- bool RBL::lookup(const char* name, PIP4_ADDRESS result)
- {
- if(!name || !result)
- return false;
- /* Set dns server to query.
- It is important to not use the users DNS servers - some ISPs hijack non existing domains.
- That could be misinterpreted. */
- IP4_ARRAY serverList = {1, inet_addr("8.8.8.8")};
- PDNS_RECORD pDnsRecord = NULL;
- DNS_STATUS status = DnsQuery_A(name, DNS_TYPE_A, DNS_QUERY_STANDARD, &serverList, &pDnsRecord, NULL);
- // status == 9003 would mean no assosciated IP thus not in the RBL
- if(DNS_RCODE_NOERROR != status)
- {
- return false;
- }
- for (PDNS_RECORD pRecord = pDnsRecord; pRecord != NULL; pRecord = pRecord->pNext)
- {
- printf("%X\n", pRecord->Data.A.IpAddress);
- }
- // No need for anything more than one result.
- *result = pDnsRecord->Data.A.IpAddress;
- DnsRecordListFree(pDnsRecord, DnsFreeRecordListDeep);
- return true;
- }
- void RBL::build_request_domain(const std::string& ip, const std::string& end, std::string& result)
- {
- std::vector<std::string> ipParts;
- string_explode(ip, ".", ipParts);
- result = ipParts.at(3) + "." + ipParts.at(2) + "." + ipParts.at(1)
- + "." + ipParts.at(0) + "." + end;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement