Advertisement:

Author Topic: Who's Online Automatically Resolve IP  (Read 688 times)

Offline njtweb

  • Full Member
  • ***
  • Posts: 504
Who's Online Automatically Resolve IP
« on: June 12, 2018, 08:50:09 PM »
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?

Offline Chen Zhen

  • Sophist Member
  • *****
  • Posts: 1,125
  • Gender: Male
  • If you're going through hell, keep going!
    • Underdog-01 on GitHub
    • WebDev.ca
Re: Who's Online Automatically Resolve IP
« Reply #1 on: June 12, 2018, 10:55:36 PM »
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...)
Code: [Select]
# 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:
Code: [Select]
// 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.

Offline njtweb

  • Full Member
  • ***
  • Posts: 504
Re: Who's Online Automatically Resolve IP
« Reply #2 on: June 13, 2018, 08:31:25 AM »
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.

Offline Chen Zhen

  • Sophist Member
  • *****
  • Posts: 1,125
  • Gender: Male
  • If you're going through hell, keep going!
    • Underdog-01 on GitHub
    • WebDev.ca
Re: Who's Online Automatically Resolve IP
« Reply #3 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?

Offline njtweb

  • Full Member
  • ***
  • Posts: 504
Re: Who's Online Automatically Resolve IP
« Reply #4 on: June 17, 2018, 05:46:00 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.

Offline Chen Zhen

  • Sophist Member
  • *****
  • Posts: 1,125
  • Gender: Male
  • If you're going through hell, keep going!
    • Underdog-01 on GitHub
    • WebDev.ca
Re: Who's Online Automatically Resolve IP
« Reply #5 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.


Offline njtweb

  • Full Member
  • ***
  • Posts: 504
Re: Who's Online Automatically Resolve IP
« Reply #6 on: June 18, 2018, 11:56:48 AM »

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.