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

Issue 23: Add method to get and display IP address on vebose #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 8 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, time, os, socket, fcntl, struct
from prompt_toolkit import print_formatted_text, HTML
from websockets.exceptions import ConnectionClosedError
from utils.helper_display import HelperDisplay
Expand Down Expand Up @@ -87,6 +87,12 @@ def servenow(netpdata="127.0.0.1", chatport="9696"):
print_formatted_text(HTML("[" + obtntime() + "] " + "<b>SNCTRYZERO</b> > <red><b>SNCTRYZERO server was shut down</b></red>"))
sys.exit()


def getipaddr():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
Comment on lines +91 to +94
Copy link
Owner

Choose a reason for hiding this comment

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

The IP address provided here would be restricted to only IPv4 addresses.

Take a look at this.

image

Even when IPv6 is selected, only the IPv4 address is displayed.

Also, the displayed IP address is not very useful when communicating across dissimilar networks as the address is applicable only in the intranet.

image



@click.command()
@click.option("-c", "--chatport", "chatport", help="Set the port value for the server [0-65536]", required=True)
Expand All @@ -107,6 +113,7 @@ def mainfunc(chatport, netprotc):
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 : "+ getipaddr() +"</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