Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta v0.3 #11

Merged
merged 5 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<a href=""><img src="image/w3b13locker.jpg" title="w3b13locker" alt="w3b13locker"></a>
# w3bsite 13locker
`beta build v0.2`
`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

> 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
## Table of Contents
- [Requirements](#requirements)
- [Installation](#installation)
- [Features](#features)
Expand All @@ -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
Expand All @@ -45,19 +45,20 @@ 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
- 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`
Expand All @@ -76,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
Expand Down Expand Up @@ -111,6 +113,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
Expand All @@ -128,6 +133,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



Binary file modified __pycache__/config.cpython-37.pyc
Binary file not shown.
Binary file removed __pycache__/func.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/logger.cpython-37.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions changeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
* 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
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def config() :
if myos=='Windows':
windir=os.environ['windir']
hostPath=windir+r'\system32\drivers\etc\hosts'
if myos=='Linux':
if myos=='Linux' or myos=='Darwin':
hostPath=r'/etc/hosts'
pathFile=open(r'data/path.txt','w')
pathFile.write('operatingSystem|'+myos+'\n'+'hosts|'+hostPath+'\n')
Expand Down
41 changes: 0 additions & 41 deletions data/hostsOrginal.txt
Original file line number Diff line number Diff line change
@@ -1,41 +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





Empty file added data/log.ini
Empty file.
2 changes: 0 additions & 2 deletions data/path.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
operatingSystem|Windows
hosts|C:\Windows\system32\drivers\etc\hosts
9 changes: 9 additions & 0 deletions logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#write log.ini
#author : Samartha
import datetime as dt
def log(logDetails):
logFile=open(r'data/log.ini','a+')
now = dt.datetime.now()
now = now.strftime("%Y-%m-%d_%H:%M:%S")
logFile.write(now+'_'+logDetails+'\n')
logFile.close()
68 changes: 49 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#w3b13locker by Samartha
import sys
import os
import config as c
import logger as l
#hostsFile=r'hosts.txt'
hostsFile=c.config()
def searchDomain(dom):
Expand All @@ -21,7 +23,6 @@ def searchDomain(dom):
return index
else:
return -1
# rHost=open(r'hosts.txt','r')
argc = len(sys.argv)
if argc>1 and argc<=4 :
option = sys.argv[1]
Expand All @@ -34,40 +35,69 @@ 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 :
if option=='-b' or option=='--block' :
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' :
Expand Down