News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Who's Online Automatically Resolve IP

Started by njtweb, June 12, 2018, 08:50:09 PM

Previous topic - Next topic

njtweb

Is there a mod that would automatically resolve an IP to the ISP carrier instead of clicking on it to resolve by region?  Basically instead of showing the IP, it shows the carrier name like Verizon, Comcast, Cox, Lightspeed etc?

Chen Zhen

There are a few ways to accomplish this but it is not available in PHP by default.

[1]
You can use DOM to scrape an API to gather that data.
ie API ref.
https://www.domaintools.com/resources/api-documentation/whois-lookup/




[2]
If you have direct access to your OS via a terminal then you can install whois & use PHP to execute a whois lookup.

ie. install whois on a Linux distro
here are commands for 3 OS (use the one that suits you from the three...)

# yum install whois #RHEL/CentOS
# dnf install whois #Fedora 22+
$ sudo apt install whois #Debian/Ubuntu


Then you can use PHP to gather different data from an IP address.
With this example we gather the organization name of the ISP from SMF:

// One of SMF IPv4 addresses: 66.71.247.134
$output = shell_exec("whois 66.71.247.134 2>&1");
$allInfo = '<pre>' . $output . '</pre>';
$array = preg_split ('/$\R?^/m', $allInfo);


function stristrarray($array, $str)
{
foreach($array as $k => $v)
{
if(stristr($v, $str))
{
$index = $k;
break;
}
}
return !empty($index) ? $array[$index] : '';
}

//OrgName returns the ISP organization hosting the IP address
$result = str_replace('OrgName: ', '', stristrarray($array, 'OrgName'));
echo $result;





There might be another way of doing it using another OS tool via shell_exec()
or perhaps whois has more specific commands to gather less data or specific data per query.
What I propose here is ok for the admin clicking on an IP to see its specific data but to have it populate a large list of users online (including guests) will likely result in a slow page load.

With some basic PHP & HTML knowledge, you should be able to implement that.

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

njtweb

Ok, I was thinking more along the line of a mod package, I don't have any confidence in myself making these kinds of changes. So, no big deal.

Chen Zhen

Well someone can make you a small mod to make changes to that effect.
If you do not have access to install whois (ie. you use shared or free hosting) then it will have to likely use an API such as the one I suggested.

Do you use free, shared, VPS or dedicated hosting?

My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

njtweb

Quote from: Chen Zhen on June 13, 2018, 05:24:34 PM
Well someone can make you a small mod to make changes to that effect.
If you do not have access to install whois (ie. you use shared or free hosting) then it will have to likely use an API such as the one I suggested.

Do you use free, shared, VPS or dedicated hosting?

I do not have dedicated or VPS, I have Godaddy Ultimate shared hosting (Linux/Apache). Only C-Panel access for me.

Chen Zhen


In that case you need a script that uses an API to retrieve that information.
There are some readily available on GitHub that need to be adapted for use within SMF.
Someone can also develop one for you from scratch using an API & DOM to retrieve the data such as I suggested.
I'd do it for kicks & might in the future but at the moment I don't have the time.
Someone might read this thread & rig it up for you though.


My SMF Mods & Plug-Ins

WebDev

"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

njtweb

Quote from: Chen Zhen on June 17, 2018, 09:23:08 PM

In that case you need a script that uses an API to retrieve that information.
There are some readily available on GitHub that need to be adapted for use within SMF.
Someone can also develop one for you from scratch using an API & DOM to retrieve the data such as I suggested.
I'd do it for kicks & might in the future but at the moment I don't have the time.
Someone might read this thread & rig it up for you though.

Thank you for the info, it's greatly appreciated. I'm amazed at what all of you guys can do with developing tools which automate functionality. Wish I had half of the wisdom you guys have.

Advertisement: