From 1b90f0cd4b2d65652e86906859c9379a71137c57 Mon Sep 17 00:00:00 2001 From: Samartha <41548444+yunghog@users.noreply.github.com> Date: Thu, 16 Apr 2020 18:45:40 +0530 Subject: [PATCH 1/4] beta build v0.3 --- README.md | 9 ++-- __pycache__/config.cpython-37.pyc | Bin 541 -> 557 bytes __pycache__/func.cpython-37.pyc | Bin 495 -> 0 bytes __pycache__/logger.cpython-37.pyc | Bin 0 -> 425 bytes changeLog.txt | 4 ++ config.py | 2 +- data/hostsOrginal.txt | 4 -- data/log.ini | 7 +++ logger.py | 9 ++++ main.py | 68 +++++++++++++++++++++--------- 10 files changed, 73 insertions(+), 30 deletions(-) delete mode 100644 __pycache__/func.cpython-37.pyc create mode 100644 __pycache__/logger.cpython-37.pyc create mode 100644 data/log.ini create mode 100644 logger.py diff --git a/README.md b/README.md index e7228e9..88b5a9c 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ > Beta Build v0.2 -[![Build Status](http://img.shields.io/travis/badges/badgerbadgerbadger.svg?style=flat-square)](https://github.com/yunghog/w3bsite13locker) -[![Dependency Status](http://img.shields.io/gemnasium/doge/wow.svg)](https://github.com/yunghog/w3bsite13locker) +[![Build Status](https://img.shields.io/badge/version-v0.2-green?style=flat-square)](https://github.com/yunghog/w3bsite13locker) +[![Python](https://img.shields.io/badge/python-3.7-orange?style=flat-square&logo=python)](https://github.com/yunghog/w3bsite13locker) # Table of Contents - [Requirements](#requirements) @@ -34,7 +34,7 @@ ```shell git clone https://github.com/yunghog/w3bsite13locker.git ``` -### Setting up +### Setting up - open a command prompt/terminal with admin rights (*run as administrator) or a python console inside the cloned directory - run setup.py using command ```shell @@ -128,6 +128,3 @@ python main.py -unblock [domain] - 🍴 Fork this repo! - 👯 Clone this repo to your local machine using `https://github.com/yunghog/w3bsite13locker.git` - Pull requests - - - diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc index 61852ad36345b2c236dbcca202f3034e0b727a2c..13bd1221c4b08ca32a112cf132629de88a097349 100644 GIT binary patch delta 108 zcmbQsvX+I{iI z<{IV&tSOu|4B`waTtLh%&QQYyVJ~E41hRt}GlUNHGM9zdiIGdoxola}DzX))bB! o262WIP9WwIXQ*LYx15FLB%&4*e9?FkOORH_sX6{rVLg{le);s8;k9xAN@QdqlW$!49}E~J(B z1V4cv&>Z znBu=EV=6hOp1ACcjq`5T&wb9|XrcuO;0@rugA}V7z&&|1|KxQNk}JNTt3)LWR*U(| zAdcwMvsx+<erH^UCZC|A|8&KdXeL*!p+c_cJBNoIcFqOhl1%6Db z1rU~N_m>z>k=e+)E4IC2on^D*@&?h9QJ9&o;=c#HD@q-O)gu+9o0Wx+GB1tOy;e+= znP%d&9DR+lsFa>(se9i%I!g7SaB!AIrClcGM`rqm>?4d=J$<`B99Z*B=iUtm7k+H2 z;g7v9uJHQ#UTN})w!_o&D&L)5#5Jc!HXoyVR8$h(ZVN diff --git a/__pycache__/logger.cpython-37.pyc b/__pycache__/logger.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e8ec46690c0db2b6e105df901123a8560e4537af GIT binary patch literal 425 zcmYjOO-sW-5S`sk+7R1=AodsJ5Na#ZTM;RK;l)zu$q+0tyVle+DZ4ABr9J6?@Y)>x zOMCU?)uSgT0l``3&6~H(%rbl4Y`TEf{(ir=2*78V{24_uKvxF{95_iKAe?gc1_9+{ z48HY+H!zH`vNDEfp@N;z4 z4@WYeiCC*}w9-#`7A|`a3cH;2(mZ|^GQ_&6kln?~Fr?)URJB;*R_Bn&CTc#DH4M@& bp%khC|Db`IaZcwse@VqzxlUF7f1 and argc<=4 : option = sys.argv[1] @@ -34,13 +35,32 @@ def searchDomain(dom): print('Invalid set of arguments\nUse -h/--help to display valid options') if argc==2 : if option=='-l' or option=='--list' : + os.system('cls') + print('------------hosts-------------') rHost=open(hostsFile,'r') for line in rHost : if line[0] != '#' : print(line, end='') rHost.close(); elif option=='-h' or option=='--help' : - print('all the possible option combinations !!') + os.system('cls') + help='''Usage: python main.py [option] [arguments] + python main.py [-b/-ub/-s/-h/l/--block/--unblock/--search/--list/--help] *[-f/--file] *[domain/domain list]\n ++----------------+-----------------------------------------------+ +| option | description | ++----------------+-----------------------------------------------+ +| -b/--block | blocks the domain. takes domain as argument | +| -ub/--unblock | unblocks the domain. takes doamin as argument | +| -s/--search | search for a domain. takes domain as argument | +| -l/--list | list blocked domain | +| -f/--file | used along with -b/--block or -ub/--unblock. | +| | takes domain list | ++----------------+-----------------------------------------------+ + ----------w3b13locker---------- + ---stable build v1.0--- + --by Samartha-- +''' + print(help) else: print('Invalid argument\nUse -h/--help to display valid options') if argc==3 : @@ -48,26 +68,36 @@ def searchDomain(dom): if searchDomain(domain)>=0: print(domain, ' is already blocked') else: - wHost=open(hostsFile,'a') - wHost.write('\n') - block='127.0.0.1 ' + domain - wHost.write(block) - wHost.close() + try: + wHost=open(hostsFile,'a') + wHost.write('\n') + block='127.0.0.1 ' + domain + wHost.write(block) + wHost.close() + l.log('blocked_'+domain) + except PermissionError : + l.log('failed_to_block_'+domain+'_Error:Access denied') + print('Failed! Access denied! Open console with admin rights') elif option=='-ub' or option=='--unblock' : index=searchDomain(domain) if index>=0: - rHost=open(hostsFile,'r') - dList=rHost.read().split('\n') - rHost.close() - wHost=open(hostsFile,'w') - for dom in dList: - if '#' in dom : - wHost.write(dom+'\n') - if '#' not in dom and dom!='\n' and dom!='': - xDom=dom.split(' ') - if domain!=xDom[1]: - wHost.write(xDom[0]+' '+xDom[1]+'\n') - wHost.close() + try: + rHost=open(hostsFile,'r') + dList=rHost.read().split('\n') + rHost.close() + wHost=open(hostsFile,'w') + for dom in dList: + if '#' in dom : + wHost.write(dom+'\n') + if '#' not in dom and dom!='\n' and dom!='': + xDom=dom.split(' ') + if domain!=xDom[1]: + wHost.write(xDom[0]+' '+xDom[1]+'\n') + wHost.close() + l.log('unblocked_'+domain) + except PermissionError : + l.log('failed_to_unblock_'+domain+'_Error:Access denied') + print('Failed! Access denied! Open console with admin rights') else: print(domain , ' domain is not in the hosts') elif option=='-s' or option=='--search' : From 305c7f79d17200155ca2467fd2af20c7a48f94d2 Mon Sep 17 00:00:00 2001 From: Samartha <41548444+yunghog@users.noreply.github.com> Date: Thu, 16 Apr 2020 18:53:13 +0530 Subject: [PATCH 2/4] beta v0.3 --- README.md | 10 +++++++--- data/hostsOrginal.txt | 37 ------------------------------------- data/log.ini | 7 ------- data/path.txt | 2 -- 4 files changed, 7 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 88b5a9c..3721e6d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ w3b13locker # w3bsite 13locker -`beta build v0.2` +`beta build v0.3` ### web blocker | w3b13locker | website blocker > Block inapropriate websites and ads by their domain @@ -9,9 +9,9 @@ > Build with python 3.7 -> Beta Build v0.2 +> Beta Build v0.3 -[![Build Status](https://img.shields.io/badge/version-v0.2-green?style=flat-square)](https://github.com/yunghog/w3bsite13locker) +[![Build Status](https://img.shields.io/badge/version-v0.3-green?style=flat-square)](https://github.com/yunghog/w3bsite13locker) [![Python](https://img.shields.io/badge/python-3.7-orange?style=flat-square&logo=python)](https://github.com/yunghog/w3bsite13locker) # Table of Contents @@ -45,6 +45,7 @@ python setup.py - Working with hosts file - Compatible on Windows and Linux machines - Lightweight python script +- Log file to keep track of hosts - Easy to handle ## Usage @@ -111,6 +112,9 @@ python main.py -unblock [domain] * bugs fixed - works on linux os - hosts file with domains separated by '\t' problem resolved +# w3b13locker beta v0.3 : + - compatible on mac os + - working log file @ data/log.ini which holds all logs ``` ## Snapshot diff --git a/data/hostsOrginal.txt b/data/hostsOrginal.txt index 1bad9cc..e69de29 100644 --- a/data/hostsOrginal.txt +++ b/data/hostsOrginal.txt @@ -1,37 +0,0 @@ -# Copyright (c) 1993-2009 Microsoft Corp. -# -# This is a sample HOSTS file used by Microsoft TCP/IP for Windows. -# -# This file contains the mappings of IP addresses to host names. Each -# entry should be kept on an individual line. The IP address should -# be placed in the first column followed by the corresponding host name. -# The IP address and the host name should be separated by at least one -# space. -# -# Additionally, comments (such as these) may be inserted on individual -# lines or following the machine name denoted by a '#' symbol. -# -# For example: -# -# 102.54.94.97 rhino.acme.com # source server -# 38.25.63.10 x.acme.com # x client host -# localhost name resolution is handled within DNS itself. -# 127.0.0.1 localhost -# ::1 localhost -127.0.0.1 www.r2rdownload.com -127.0.0.1 www.elephantafiles.com -127.0.0.1 localhost -::1 localhost -127.0.0.1 musico -::1 musico -127.0.0.1 sc -::1 sc -127.0.0.1 mixtape -::1 mixtape -127.0.0.1 yunghogbeats -::1 yunghogbeats -127.0.0.1 ekathvatheme -::1 ekathvatheme -127.0.0.1 kalasa -::1 kalasa - diff --git a/data/log.ini b/data/log.ini index 766c8f6..e69de29 100644 --- a/data/log.ini +++ b/data/log.ini @@ -1,7 +0,0 @@ -2020-04-16_11:14:35_blocked domain -2020-04-16_11:20:12_blocked_random.domain -2020-04-16_11:43:13_unblocked_random.domain -2020-04-16_12:00:32_failed_to_block_www.random.com -Error:Access denied -2020-04-16_12:03:18_failed_to_block_www.random.com -Error:Access denied diff --git a/data/path.txt b/data/path.txt index 28c1199..e69de29 100644 --- a/data/path.txt +++ b/data/path.txt @@ -1,2 +0,0 @@ -operatingSystem|Windows -hosts|C:\Windows\system32\drivers\etc\hosts From d6d43c5170fcd0cb277111bef8599cd2b0a781ed Mon Sep 17 00:00:00 2001 From: Samartha <41548444+yunghog@users.noreply.github.com> Date: Thu, 16 Apr 2020 18:56:45 +0530 Subject: [PATCH 3/4] beta build v0.3 --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3721e6d..eb65507 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ `beta build v0.3` ### web blocker | w3b13locker | website blocker -> Block inapropriate websites and ads by their domain +> Block inappropriate websites and ads by their domain > CommandLine application @@ -52,13 +52,13 @@ python setup.py - To block any domain use command (*without '[' ']' around domain name) ```shell python main.py -b [domain] -python main.py -block [domain] +python main.py --block [domain] ``` - To unblock any domain use command (*without '[' ']' around domain name) ```shell python main.py -ub [domain] -python main.py -unblock [domain] +python main.py --unblock [domain] ``` > For full usage refer usage.txt - `usage.txt` @@ -77,6 +77,7 @@ python main.py -unblock [domain] | -ub/--unblock | domain name | unblocking | | -l/--list | none | list already blocked domains | | -s/--search | domain name | find out if the domain is blocked | +| -h/--help | none | list all possible commands | +----------------+------------------+-------------------------------------+ # launch the python console in administrator mode From 1c7a7c89076268bf0cee59be2ccb70a17130f4d6 Mon Sep 17 00:00:00 2001 From: Samartha <41548444+yunghog@users.noreply.github.com> Date: Thu, 16 Apr 2020 19:26:34 +0530 Subject: [PATCH 4/4] beta build v0.3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb65507..4b86ab0 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ [![Build Status](https://img.shields.io/badge/version-v0.3-green?style=flat-square)](https://github.com/yunghog/w3bsite13locker) [![Python](https://img.shields.io/badge/python-3.7-orange?style=flat-square&logo=python)](https://github.com/yunghog/w3bsite13locker) -# Table of Contents +## Table of Contents - [Requirements](#requirements) - [Installation](#installation) - [Features](#features)