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

Improved IP address fetch & display #87

Merged
merged 1 commit into from
Oct 30, 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
14 changes: 13 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio, websockets, sys, click, time, os
import asyncio, websockets, sys, click, urllib3, time
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urllib3 is a not-so elegant module but lightweight - something which is perfect for our usecase. Thanks for replacing requests in favour of this module.

from prompt_toolkit import print_formatted_text, HTML
from websockets.exceptions import ConnectionClosedError
from utils.helper_display import HelperDisplay
Expand All @@ -20,6 +20,16 @@ def obtntime():
return timehour + ":" + timemint + ":" + timesecs


def ipaddress(v):
url = "https://api64.ipify.org"
if v == 4:
url = "https://api.ipify.org"
elif v == 6:
url = "https://api6.ipify.org"
response = urllib3.PoolManager().request('GET', url)
return response.data.decode('UTF-8')
Comment on lines +23 to +30
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work done with fetching distinct addresses.



def getallus(chatroom):
userlist = []
for indx in USERS:
Expand Down Expand Up @@ -104,9 +114,11 @@ def mainfunc(chatport, netprotc):
if netprotc == "ipprotv6":
print_formatted_text(HTML("[" + obtntime() + "] " + "<b>SNCTRYZERO</b> > <green>IP version : 6</green>"))
netpdata = "::"
print_formatted_text(HTML("[" + obtntime() + "] " + "<b>SNCTRYZERO</b> > <green>IP address : " + ipaddress(6) + "</green>"))
elif netprotc == "ipprotv4":
print_formatted_text(HTML("[" + obtntime() + "] " + "<b>SNCTRYZERO</b> > <green>IP version : 4</green>"))
netpdata = "0.0.0.0"
print_formatted_text(HTML("[" + obtntime() + "] " + "<b>SNCTRYZERO</b> > <green>IP address : " + ipaddress(4) + "</green>"))
servenow(netpdata, chatport)
except OSError:
print_formatted_text(HTML("[" + obtntime() + "] " + "<b>SNCTRYZERO</b> > <red><b>The server could not be started up</b></red>"))
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ cryptography==3.0
prompt-toolkit==3.0.6
pycparser==2.20
six==1.15.0
urllib3==1.25.10
wcwidth==0.2.5
websockets==8.1
websockets==8.1