-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add FindMyIP module to get internal IP. - Add colorama module to change text colors. - Changes ANSI codes to colorama functions.
- Loading branch information
1 parent
f1d0ab3
commit 1b34e13
Showing
1 changed file
with
22 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,43 @@ | ||
#! /usr/bin/python3 | ||
|
||
from os import chdir, getcwd | ||
from os import chdir, getcwd, system | ||
from http.server import HTTPServer, CGIHTTPRequestHandler | ||
|
||
# Import external modules | ||
try: | ||
from FindMyIP import internal | ||
except ModuleNotFoundError: | ||
system("pip install FindMyIP") | ||
from FindMyIP import internal | ||
|
||
try: | ||
from colorama import init, Fore | ||
init(autoreset=True) | ||
except ModuleNotFoundError: | ||
system("pip install colorama") | ||
from colorama import init, Fore | ||
init(autoreset=True) | ||
|
||
|
||
class ShareFile: | ||
def __init__(self): | ||
self.current_directory = getcwd() | ||
self.__port__ = int(input(f"[!] You Are sharing \"{self.current_directory}\" on your local network.\nEnter Your port here: ")) | ||
|
||
self.ok = '\033[92m' #GREEN | ||
self.fail = '\033[31m' #RED | ||
self.reset = '\033[0m' #RESET COLOR | ||
|
||
|
||
def __color__green__(self, text): | ||
return self.ok + text + self.reset | ||
|
||
self.green = Fore.GREEN | ||
self.red = Fore.RED | ||
self.reset = Fore.RESET | ||
|
||
def __server__(self): | ||
chdir(".") | ||
self.server = HTTPServer(("", self.__port__), CGIHTTPRequestHandler) | ||
print(f"Server is online on 127.0.0.1:{self.__color__green__(f'{self.__port__}')}") | ||
|
||
print(f"Server is online on {self.green}{internal()}{self.reset}:{self.red}{self.__port__}") | ||
|
||
def run(self): | ||
self.__server__() | ||
self.server.serve_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
app = ShareFile() | ||
app.run() | ||
app.run() | ||
|