-
Notifications
You must be signed in to change notification settings - Fork 34
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
Issue 23: IP address fetch and display #90
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c21d0b0
Updated IP address fetch & display
316b641
Fixed the URLs
aec9305
Completed implementing IP fetch
84d1f88
Added exceptions
44b453d
Merge remote-tracking branch 'upstream/master' into upstream
61f1a70
Revert "Merge remote-tracking branch 'upstream/master' into upstream"
683e00d
Fixed dropped requirements commit
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 +1,4 @@ | ||
import asyncio, websockets, sys, click, time, os | ||
import asyncio, websockets, sys, click, http.client, time | ||
from prompt_toolkit import print_formatted_text, HTML | ||
from websockets.exceptions import ConnectionClosedError | ||
from utils.helper_display import HelperDisplay | ||
|
@@ -20,6 +20,21 @@ def obtntime(): | |
return timehour + ":" + timemint + ":" + timesecs | ||
|
||
|
||
def ipaddress(v): | ||
url = "api64.ipify.org" | ||
if v == 4: | ||
url = "api.ipify.org" | ||
elif v == 6: | ||
url = "api6.ipify.org" | ||
try: | ||
connection = http.client.HTTPSConnection(url) | ||
connection.request("GET", "/") | ||
response = connection.getresponse() | ||
return response.read().decode("UTF-8") | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The generalized exception handling would prevent service crashes in all times. |
||
return "Error getting IP address." | ||
|
||
|
||
def getallus(chatroom): | ||
userlist = [] | ||
for indx in USERS: | ||
|
@@ -104,9 +119,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>")) | ||
|
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ prompt-toolkit==3.0.8 | |
pycparser==2.20 | ||
six==1.15.0 | ||
wcwidth==0.2.5 | ||
websockets==8.1 | ||
websockets==8.1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's as optimized as it gets. Good work!