Welcome to Geeklog Thursday, December 05 2019 @ 10:35 pm EST

Geeklog Forums

Add bots to your Whos Online Block


Status: offline

ByteEnable

Forum User
Full Member
Registered: 20/10/03
Posts: 138
This little hack will show which bots are currently indexing your site. It uses the gl_sessions table. Just add the code listed below between the two snippets in function phpblock_whosonline in lib-common.php.

PHP Formatted Code


    $result = DB_query( "SELECT DISTINCT uid,remote_ip FROM {$_TABLES['sessions']} WHERE uid = 1" );
    $num_anon += DB_numRows( $result );

<--------- Dont add the code above its just for reference


    for( $i = 0; $i < $num_anon; $i++ ) {
        $A = DB_fetchArray( $result );
        if(ereg("(^216.239.46|^64.68.8|^66.249.[64-95])",$A['remote_ip'])) {
                if ( !(strstr($retval,"Google")) ) {
                        $retval .= "Google" . '<br>';
                }
                --$num_anon;
        }
        if(ereg("(^68.142.[192-255])",$A['remote_ip'])) {
                if ( !(strstr($retval,"Yahoo! Slurp")) ) {
                        $retval .= "Yahoo! Slurp" . '<br>';
                }
                --$num_anon;
        }
        if(ereg("(^216.109.[112-127])",$A['remote_ip'])) {
                if ( !(strstr($retval,"Yahoo! Feed")) ) {
                        $retval .= "Yahoo! Feed" . '<br>';
                }
                --$num_anon;
        }
        if(ereg("(^64.4.8.[93-94]|^64.4.8.[113-117]|^65.54.164.[36-135]",$A['remote_ip'])) {
                if ( !(strstr($retval,"MSN Bot")) ) {
                        $retval .= "MSN Bot" . '<br>';
                }
                --$num_anon;
        }
    }


<-- Dont add the code below, its just for reference
    if(( $_CONF['whosonline_anonymous'] == 1 ) &&  
            ( empty( $_USER['uid'] ) || ( $_USER['uid'] == 1 )))

 


The strstr function insures that the bot is only listed once, but yet all of its IP addresses that are currently hitting your site is subtracted from the total anon users.

Regards,

Byte
LinuxElectrons
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 20/10/03
Posts: 138
In my last post, my regular expressions have some errors Embarassed

Here is the fixed code:

PHP Formatted Code

for( $i = 0; $i < $num_anon; $i++ ) {
        $A = DB_fetchArray( $result );
        if(ereg("^216\.239\.46|^64\.68\.8|^66\.249\.(6[4-9]|[78]\d|9[0-5])",$A['remote_ip'])) {
                if ( !(strstr($retval,"Google")) ) {
                        $retval .= "Google" . '<br>';
                }
                --$num_anon;
        }
        if(ereg("^68\.142\.(19[2-9]|2[01234]\d|25[012345])",$A['remote_ip'])) {
                if ( !(strstr($retval,"Yahoo! Slurp")) ) {
                        $retval .= "Yahoo! Slurp" . '<br>';
                }
                --$num_anon;
        }
        if(ereg("^216\.109\.(11[2-9]|12[0-7])",$A['remote_ip'])) {
                if ( !(strstr($retval,"Yahoo! Feed")) ) {
                        $retval .= "Yahoo! Feed" . '<br>';
                }
                --$num_anon;
        }
        if(ereg("^64.4.8.9[3-4]|^64.4.8.11[3-7]|^65.54.164.(3[6-9]|[4-9]\d|1[0-2]\d|13[0-5])",$A['remote_ip'])) {
                if ( !(strstr($retval,"MSN Bot")) ) {
                        $retval .= "MSN Bot" . '<br>';
                }
                --$num_anon;
        }
    }

 
 Quote

Status: offline

vadertech

Forum User
Full Member
Registered: 26/05/03
Posts: 329
Thanks. I will give it a try. Can you be clear on where to place it in the phpblock_whoseonline section.
GeekLog Hosting, Installations and Upgrades - WWW.AWEHOST.COM - Hosting starts @ only $4.95/mo.
 Quote

Status: offline

1000ideen

Forum User
Full Member
Registered: 04/08/03
Posts: 1294
Wouldn`t this be nicely rounded up with a line saying:

total registered users: xy

Dirk suggested to use this: DB_count($_TABLES['users']) but it appears to be only for very, very good coders... Rolling Eyes

~~~~~~
I just found a block with a total members count: http://www.geeklog.net/forum/viewtopic.php?showtopic=42960

@ vadertech did you see where it has to be placed in the first posting above? It is the quoted code. "Don't add the code above its just for reference"
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 20/10/03
Posts: 138
Here is the latest regex stuff:

PHP Formatted Code

if(eregi("^216\.239\.46|^64\.68\.8|^66\.249\.(6[4-9]|[78]\d?|9[0-5])",$A['remote_ip'])) {
               if ( !(stristr($retval,"Google")) ) {
                        $retval .= "Google<br>";
                }
                --$num_anon;
        }
        if(eregi("^68\.142\.(19[2-9]|2[01234]\d?|25[012345])|
                          ^66\.94\.(22[4-9]|2[3-4]\d?|25[0-5])|
                          ^216\.109\.(11[2-9]|12[0-7])|
                          ^206\.190\.(3[2-9]|[4-5]\d?|6[0-3])"
,$A['remote_ip'])) {
                if ( !(stristr($retval,"Yahoo!")) ) {
                        $retval .= "Yahoo!<br>";
                }
                --$num_anon;
        }
        if(eregi("^65\.(19[2-9]|2[0-1]\d?|22[0-3])",$A['remote_ip'])) {
                if ( !(stristr($retval,"Ask Jeeves")) ) {
                        $retval .= "Ask Jeeves<br>";
                }
                --$num_anon;
        }
        if(eregi("^72\.30\.|
                          ^68\.142\.(19[2-9]|2[0-5]\d?)|
                          ^66\.196\.(6[4-9]|[789]\d?|1[0-1]\d?|12[0-7])"
,$A['remote_ip'])) {
                if ( !(stristr($retval,"Inktomi")) ) {
                        $retval .= "Inktomi<br>";
                }
                --$num_anon;
        }
        if(eregi("^64.4.8.9[3-4]|^64.4.8.11[3-7]|^65.5[2-5]\.",$A['remote_ip'])) {
                if ( !(stristr($retval,"MSN Bot")) ) {
                        $retval .= "MSN Bot<br>";
                }
                --$num_anon;
        }

 
 Quote

Status: offline

vadertech

Forum User
Full Member
Registered: 26/05/03
Posts: 329
Quote by 1000ideen: @ vadertech did you see where it has to be placed in the first posting above? It is the quoted code. "Don't add the code above its just for reference"


Ah now that I look at it, it makes sense.
GeekLog Hosting, Installations and Upgrades - WWW.AWEHOST.COM - Hosting starts @ only $4.95/mo.
 Quote

Status: offline

romantaran

Forum User
Junior
Registered: 19/03/05
Posts: 34
Location:Russia
Hi, ByteEnable! I'd like to add some bots to your list, but don't know how to use regular expressions. Can you promt to me?

Here are IP's:

inetnum: 213.180.216.0 - 213.180.217.255
netname: YANDEX-216
descr: Yandex search engine
country: RU

inetnum: 81.19.64.0 - 81.19.66.255
netname: RAMTEL
descr: Rambler Telecom ISP main network
country: RU
 Quote

Status: offline

1000ideen

Forum User
Full Member
Registered: 04/08/03
Posts: 1294
Yep, I also hardly understood the coding and would like to add some more IPs.
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 20/10/03
Posts: 138
Quote by romantaran: Hi, ByteEnable! I'd like to add some bots to your list, but don't know how to use regular expressions. Can you promt to me?

Here are IP's:

inetnum: 213.180.216.0 - 213.180.217.255
netname: YANDEX-216
descr: Yandex search engine
country: RU
PHP Formatted Code

if(ereg("(^213\.180\.[216-217])",$A['remote_ip']) ) {
     if ( !(strstr($retval,"Yandex")) ) { // if Yandex is not in display list then add it
                        $retval .= "Yandex" . '<br>';
     }
     --$num_anon; // remove one ip from anonymous count because
                          // we just identified the IP as a search engine.
}

 


inetnum: 81.19.64.0 - 81.19.66.255
netname: RAMTEL
descr: Rambler Telecom ISP main network
country: RU


PHP Formatted Code

if(ereg("(^81\.19\.[64-66])",$A['remote_ip']) ) {
     if ( !(strstr($retval,"RAMTEL")) ) { // if Yandex is not in display list then add it
                        $retval .= "RAMTEL" . '<br>';
     }
     --$num_anon; // remove one ip from anonymous count because
                          // we just identified the IP as a search engine.
}

 
 Quote

Status: offline

ByteEnable

Forum User
Full Member
Registered: 20/10/03
Posts: 138
I think I made some mistakes earlier in my haste.

PHP Formatted Code

if(eregi("^213\.180\.21[6-7]",$A['remote_ip']) ) {
     if ( !(strstr($retval,"Yandex")) ) { // if Yandex is not in display list then add it
                        $retval .= "Yandex" . '<br>';
     }
     --$num_anon; // remove one ip from anonymous count because
                          // we just identified the IP as a search engine.
}


 

For Ramtel
PHP Formatted Code

if(eregi("^81\.19\.6[4-6]",$A['remote_ip']) ) {
     if ( !(strstr($retval,"RAMTEL")) ) { // if Yandex is not in display list then add it
                        $retval .= "RAMTEL" . '<br>';
     }
     --$num_anon; // remove one ip from anonymous count because
                          // we just identified the IP as a search engine.
}


 


I also upated my older IP's. I also noticed that if I had spaces or new lines inbetween the addresses that the ereg failed.

PHP Formatted Code

// The strstr function insures the bot is only displayed once.
// $num_anon is decremented for each bot IP address.  Because a spider may
// have multiple IP's when it hits.
                if(eregi("^216\.239\.46|^64\.68\.8|^66\.249\.(6[4-9]|[78]\d?|9[0-5])|^72\.14\.(19[2-9]|2[0-5]\d?)",$A['remote_ip'])) {
                        if ( !(stristr($retval,"Google")) ) {
                        $retval .= "Google<br>";
                }
                --$num_anon;
        }
        if(eregi("^68\.142\.(19[2-9]|2[01234]\d?|25[012345])|^66\.94\.(22[4-9]|2[3-4]\d?|25[0-5])|^216\.109\.(11[2-9]|12[0-7])|^206\.190\.(3[2-9]|[4-5]\d?|6[0-3])|^209\.191\.(6[4-9]|1[0-2][0-7])",$A['remote_ip'])) {
                if ( !(stristr($retval,"Yahoo!")) ) {
                        $retval .= "Yahoo!<br>";
                }
                --$num_anon;
        }
        if(eregi("^65\.(19[2-9]|2[0-1]\d?|22[0-3])",$A['remote_ip'])) {
                if ( !(stristr($retval,"Ask Jeeves")) ) {
                        $retval .= "Ask Jeeves<br>";
                }
                --$num_anon;
        }
        if(eregi("^72\.30\.|^68\.142\.(19[2-9]|2[0-5]\d?)|^66\.196\.(6[4-9]|[789]\d?|1[0-1]\d?|12[0-7])",$A['remote_ip'])) {
                if ( !(stristr($retval,"Inktomi")) ) {
                        $retval .= "Inktomi<br>";
                }
                --$num_anon;
        }
        if(eregi("^64.4.8.9[3-4]|^64.4.8.11[3-7]|^65.5[2-5]\.",$A['remote_ip'])) {
                if ( !(stristr($retval,"MSN Bot")) ) {
                        $retval .= "MSN Bot<br>";
                }
                --$num_anon;
        }


 
 Quote

Status: offline

romantaran

Forum User
Junior
Registered: 19/03/05
Posts: 34
Location:Russia
Yes, there was a problem with the ereg. Thank you!
 Quote

Status: offline

Dazzy

Forum User
Full Member
Registered: 19/07/03
Posts: 200
Location:N. Ireland
Does anyone have a working example of this? I keep getting unexpected $end at end of the file on a test site

Thanks
Dazzy
 Quote

All times are EST. The time is now 10:35 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content