[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
A message from @CodeMonkeyZ, 2ch lead developer: "How Hiroyuki Nishimura will sell 4chan data"
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


34c7a3 No.3219

So /tech doesn't like my code so I'll share it with all of you :-)

Website Blocker

#include<stdio.h>

#include<dos.h>

#include<dir.h>

char site_list[6][30]={

"google.com",

"www.google.com",

"youtube.com",

"www.youtube.com",

"yahoo.com",

"www.yahoo.com",

"bing.com",

"www.bing.com",

"4chan.org",

"www.4chan.org",

"8ch.net",

"www.8ch.net",

"duckduckgo.com",

"www.duckduckgo.com",

"google.ac",

"www.google.ac",

"google.ad

"www.google.ad",

"google.ae",

"www.google.ae",

"google.af",

"www.google.af",

"google.ag",

"www.google. ag",

};

char ip[12]="127.0.0.1";

FILE *target;

int find_root(void);

void block_site(void);

int find_root()

{

int done;

struct ffblk ffblk;//File block structure

done=findfirst("C:\\windows\\system32\\drivers\\etc\\hosts",&ffblk,FA_DIREC); /*to determine the root drive*/

if(done==0)

{

target=fopen("C:\\windows\\system32\\drivers\\etc\\hosts","r+"); /*to open the file*/

return 1;

}

done=findfirst("D:\\windows\\system32\\drivers\\etc\\hosts",&ffblk,FA_DIREC); /*to determine the root drive*/

if(done==0)

{

target=fopen("D:\\windows\\system32\\drivers\\etc\\hosts","r+"); /*to open the file*/

return 1;

}

done=findfirst("E:\\windows\\system32\\drivers\\etc\\hosts",&ffblk,FA_DIREC); /*to determine the root drive*/

if(done==0)

{

target=fopen("E:\\windows\\system32\\drivers\\etc\\hosts","r+"); /*to open the file*/

return 1;

}

done=findfirst("F:\\windows\\system32\\drivers\\etc\\hosts",&ffblk,FA_DIREC); /*to determine the root drive*/

if(done==0)

{

target=fopen("F:\\windows\\system32\\drivers\\etc\\hosts","r+"); /*to open the file*/

return 1;

}

else return 0;

}

void block_site()

{

int i;

fseek(target,0,SEEK_END); /*to move to the end of the file*/

fprintf(target,"\n");

for(i=0;i<6;i++)

fprintf(target,"%s\t%s\n",ip,site_list[i]);

fclose(target);

}

void main()

{

int success=0;

success=find_root();

if(success)

block_site();

}

e77638 No.3221

your code is garbage and you should feel bad


34c7a3 No.3222

>>3221

Well can you provide a better version?

Also no wonder /tech/ didn't want it


afabd4 No.3223

>>3221

What's wrong with it? It's amazing.


34c7a3 No.3225

>>3223

Thank you


34c7a3 No.3230

Might use this, thanks Anon


34c7a3 No.3231

Here's another version

#include<fstream>
#include<vector>

int main()
{
std::vector<std::string> site_list = {
"google.com",
"www.google.com",
"youtube.com",
"www.youtube.com",
"yahoo.com",
"www.yahoo.com",
"bing.com",
"www.bing.com",
"4chan.org",
"www.4chan.org",
"8ch.net",
"www.8ch.net",
"duckduckgo.com",
"www.duckduckgo.com",
"google.ac",
"www.google.ac",
"google.ad",
"www.google.ad",
"google.ae",
"www.google.ae",
"google.af",
"www.google.af",
"google.ag",
"www.google.ag"};

std::string ip = "127.0.0.1";
std::string host_file_path = ":\\Windows\\System32\\Drivers\\etc\\hosts";
std::ofstream host_file;

for(char drive = 'C'; drive < 'G'; drive++)
{
host_file.open(std::string(1, drive) + host_file_path, std::ios::app);

if(host_file.is_open())
{
for(int i = 0; i < site_list.size(); ++i)
{
host_file << ip << "\t" << site_list[i] << std::endl;
}
host_file.close();
break;
}
}
return 0;
}


65d77b No.3249

>>3219

>A fucking C program just to do simple hosts-based hostname blocking

>Hardcoded sites

>Hardcoded loopback address

>Hardcoded paths

>Broken site_list (you load a 6-dimension char array with dozens of entries, and you have a missing comma and double-quote. Some sites have random spaces in them)

>Hard-set size on arrays for static strings

>global variables with generic names

>Not checking file for existence before adding site

>single-use functions that don't improve clarity, reduce code-reuse, or improve modularity at all

>dos.h

>dir.h

>All that horrible fucking code repetition

>Not just using %WINDIR% to find the Windows install directory

This is awful, even for a beginner. You can replicate your script much better in no more than 3 lines of any shell scripting language. It's really one of the worst C programs I've ever seen.

>>3231

That's slightly better, but still shit.

You also don't have to close any fstream manually, destruction will do that automatically.


65d77b No.3250

>>3230

We have IDs here, you fucking retard.


9204d7 No.3264

>>3250

It's not the same person. It's maybe his little sister.




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]