The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 22, 2019, 06:11:06 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Botbase as Directories Function  (Read 3620 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: October 29, 2008, 08:44:31 AM »

The setbots function will take a list of IPs and turn them into a directory tree.
the isbot function purely checks to see if an IP exists as a directory path.

Setup Function
Code:
function setbots($iplist,$rootpath)
{
//iplist is a line seperated list of IPs. 1 full IP per line.
//root path must be writable by the web user
$perms = 0777; //set to minimum that will work for you. I needed 777 for a reason but 611 should work for most
umask(0);
$ips = explode("\n",str_replace("\r\n","\n",$iplist));
foreach ($ips as $ip)
{
$parts = explode('.',$ip);
mkdir($rootpath.$parts[0],$perms);
mkdir($rootpath.$parts[0].'/'.$parts[1],$perms);
mkdir($rootpath.$parts[0].'/'.$parts[1].'/'.$parts[2],$perms);
mkdir($rootpath.$parts[0].'/'.$parts[1].'/'.$parts[2].'/'.$parts[3],$perms);
}
}

Tester function
Code:
function isbot($rootpath)
{
$ip = explode('.',$_SERVER['REMOTE_ADDR']);
if (is_dir($rootpath.$ip[0].'/'.$ip[1].'/'.$ip[2].'/'.$ip[3]))
{
return true;
}
else
{
return false;
}
}
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: October 29, 2008, 09:14:24 AM »

That's actually quite sweet NBs, and I forgot that you can mkdir on something that already exists and it will simply fail ( D'oh! ) because I have a different application that needs just such a thing.

BTW, this would be a quicker eval:

Code:
<?php

function isbot($rootpath)
{
$ip explode('.',$_SERVER['REMOTE_ADDR']);
return is_dir("$rootpath.{$ip[0]}/{$ip[1]}/{$ip[2]}/{$ip[3]}");
}

?>


( note specifically lack of string concatenations )
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: October 29, 2008, 10:34:02 AM »

cool. I tend to write verbose code with the intent of coming back to streamline it. Then I usually get distracted and forget. lol
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #3 on: October 29, 2008, 09:41:43 PM »

You're doing this for IP delivery purposes I guess.

So, one could also just create filenames from IPs.

/ips/233.432.45.23
/ips/233.432.45.444
/ips/233.432.45.12

or even with a .txt extension, not that that matters.

Then check if file exists.

It's a good idea overall.

Thanks,
Bompa
Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #4 on: October 29, 2008, 10:05:17 PM »

the reason for directories instead of files is overhead for scanning all those files. since each octet is broken up, the max number of directories to scan at each level of the tree is 255 (actually less). as a result the directory scan is at most 255x4= 1024. but with files its 10s of thousands with even the smallest botbase. Some systems even have limitations on number of files per directory, usually restricted by the host company, just to prevent misuse.

the directory tree was an epiphany moment in a conversation with perk a few months ago.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #5 on: October 30, 2008, 01:31:01 AM »

the reason for directories instead of files is overhead for scanning all those files.

I don't understand.

I thought we would be looking up the incoming IP.

If the incoming IP is 124.333.22.32, then checking would just be

if(-e '124.333.22.32.txt') { print "FOUND"; }

Either that one particular file exists or it does not.  Right?

I'm probably thinking of something else, I really have not been doing much
IP cloaking.  (read, been doing none, heh)

Bompa
Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #6 on: October 30, 2008, 02:38:22 AM »

I believe it's to do with how fast it can find a directory path versus checking if a specific file exists Bomps.

DM
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #7 on: October 30, 2008, 07:16:51 AM »

right. DM.

files are stored on disk, as actual bits and with a pointer(s) in the MFT. Directories however are stored only in the MFT, with no actual files. So to find a file requires at least 2 lookups in the MFT and then I assume a 3rd physical check to make sure the data is actually there and its not an orphan. At least thats how its "supposed" to work. lol

Just remember MFT is a database just like any other, and the more rows/records you have the longer it takes to find something as well. So even if my explanation above is wrong because of the type of filesystem, it sill is a numbers game then.

make send bomps? You are right, this is for IP delivery of course.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!