Krysti.Engineer Official Chat
You are viewing an inferior version of the site because your browser does not support WebP. Do upgrade to something like Chrome or Firefox. Loading websites like this causes them to require a fallback set of images and they are almost always lower quality and larger in size.

Using IPHub.Info To Stop VPNs and Bad Traffic

IPHub.Info has a free and paid service you can use to help return data on IP addresses if they're connected to some level of "troublesome" behaviour. This site also returns known VPNs and this can be helpful for places where VPN use is heavily favoured by people to troll, like a comment section or forum. I don't recommend this for blocking READING a site, just adding data.
2022-07-21T:00:00:00+00:00 July 21 2022 00:00:00

CREATE TABLE IF NOT EXISTS `ip_whois` (
  `whois_id` int(11) NOT NULL AUTO_INCREMENT,
  `whois_ip` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
  `whois_data` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`whois_id`),
  KEY `whois_ip` (`whois_ip`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

First we need to create a very simple table to store our returned data. We don't REALLY want to repeat things. If using the free tier that misstep could push your needs into a paid subscription.

<?php
// Here you would use your project's MySQL processor to perform this part.
$db = Factory::load("DB");
$db->my_addParam("ip",$ip);
$query = "SELECT * FROM ip_whois WHERE whois_ip='{ip}'";
$wq = $db->my_Query($query);
if($db->my_Rows($wq)>0) {
	$wqa = $db->my_Fetch($wq);
	$isbad = $wqa['whois_data'];
} else {
	/* This is the important part really */
	$ch = curl_init();
	curl_setopt_array($ch, [
		CURLOPT_URL => "http://v2.api.iphub.info/ip/".$_SERVER['REMOTE_ADDR'],
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_HTTPHEADER => ["X-Key: your_api_key_here"] // Change this
	]);
	$isbad =  json_decode(curl_exec($ch))->block;
	/* end */
	// Here you would use your project's MySQL processor to perform this part.
	$db->my_addParam("ip",$_SERVER['REMOTE_ADDR']);
	$db->my_addParam("wdata",$isbad);
	$query = "INSERT INTO ip_whois (whois_ip,whois_data) VALUES ('{ip}','{wdata}')";
	$iw = $db->my_Query($query);
	if($isbad == 1) {
		/* Do something */
	}
}
?>

Now we process the IP address into our database if it's not in there. This example is more like a skeleton. It won't work out of the box cuz you'd need the MySQL processor with it but I outlined the important part and left the rest as a sort of example of how you COULD fit it into your existing project and how it SHOULD be handled as to not overload the IPHub.Info allowance you're given. The '$isbad' variable in the example will return greater than 0 if the IP address is in the blocklist database. However, if the return code is '2' then you might have a false positive so we're only catching IP's that has a return value of '1'.

Contact Krysti

@itskrystibitch Twitter Photo
Twitter:
@KrystiOnline
Facebook:
@KrystiOnline
IRC:
Official Chat
Direct.Me:
@Krysti
Ko-fi:
@Krysti
Photos:
Virtual Krysti
E-Mail / Notify of errors:
coder [@] krysti.engineer
Please be patient contacting me, I don't really check much of social media or anything. If you use the IRC be sure to stick around because that's how IRC works, silly. :P