[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][Options][ watchlist ]

/prog/ - Programming

Programming board

Catalog

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

[–]

d642a3 (5) No.3219>>3249 [Watch Thread][Show All Posts]

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();

}

7b7252 (1) No.3221>>3222 >>3223

your code is garbage and you should feel bad


d642a3 (5) No.3222

>>3221

Well can you provide a better version?

Also no wonder /tech/ didn't want it


f02b1a (1) No.3223>>3225

>>3221

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


d642a3 (5) No.3225

>>3223

Thank you


d642a3 (5) No.3230>>3250

Might use this, thanks Anon


d642a3 (5) No.3231>>3249

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;
}


08b035 (2) No.3249

>>3219 (OP)

>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.


08b035 (2) No.3250>>3264

>>3230

We have IDs here, you fucking retard.


931a34 (1) No.3264

>>3250

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




[Return][Go to top][Catalog][Screencap][Update] ( Scroll to new posts) ( Auto) 5
9 replies | 0 images | 5 UIDs | Page ?
[Post a Reply]
[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][ watchlist ]