Closed jovanbulck closed 9 years ago
Although netlogin.kuleuven.be can't be reached from home via a web browser, it does respond to ping requests. So we need another technique to figure out if the user is on KotNet or not. This may also explain the problems you were having running kotnetcli
on-campus.
Some alternatives:
mechanize
is able to load a valid HTML file from netlogin.kuleuven.beI found something interesting you should test: https://admin.kuleuven.be/icts/english/kotnet/diagnosis
Note the bold note at the bottom ;-)
Very interesting, we should check if this works both at home and at kot.
At home:
The server does respond to ping -s 1472 -c 100 134.58.126.3
KotNet's broadcast addres is 10.92.39.255
. Maybe we can use that to determine if we're on the KU Leuven network.
I can't test now in dev
branch since dev still crashes on communicator factory pattern:
Traceback (most recent call last): File "./kotnetcli.py", line 317, in
aanstuurderObvArgumenten(argumentenParser()) File "./kotnetcli.py", line 247, in aanstuurderObvArgumenten fab = LoginCommunicatorFabriek() NameError: global name 'LoginCommunicatorFabriek' is not defined
I could create a patch from your commit and apply it to master locally to see if it works, but looking at the code I wonder whether it will because gateway is defined as xx.xx.xx.xx
Then again, ideally we would find a better way as the standard gatway address is that of the NAT router inside kot I think. So it wont be the same on all kots and may clash likely with another home default gateway...
Hi, could you run this code snippet? (First install netifaces
using pip
)
import netifaces
print netifaces.gateways()["default"][netifaces.AF_INET][0]
What IP does it return? We need to check this on different kots.
@Wouter92 could you do the same?
I'm pretty sure it's a bad strategy since one has control over once own default gateway on network setup (so even if most of kotnets setups have the same default gateway its still ugly.) I'll think about something better...
I'll try this evening on kot. If helpful, this is the default gateway in the library (non-kotnet):
10.43.127.254
It's probably easy: instead of pinging netlogin.kuleuven.be we should see if we can open a https connection
nmap -p 443 netlogin.kuleuven.be
or so will probably do the job...
I'm pretty sure it's a bad strategy since one has control over once own default gateway on network setup
I'm not so sure about that, actually. IIRC, KotNet manages the DHCP and thus hands out the IP's . The routers on-kot merely act as a switch.
It's probably easy: instead of pinging netlogin.kuleuven.be we should see if we can open a https connection
Good idea.
I'm not so sure about that, actually. IIRC, KotNet manages the DHCP and thus hands out the IP's . The routers on-kot merely act as a switch.
Yep indeed, I'm not sure neither. I think however the default gateway is the first router in line to send requests to; it can subsequently forward if needed. I"m back in doubt however. You could very well be right...
Anyway: here's the result
10.92.32.1
and the nmap trick above seems to work on kot and not in library :-) So maybe this is the way to go (there will surely be some python support to try set up a TCP connection on port 433 which is https)
This is my result:
10.92.80.1
Thank you both for testing this. It seems like Kotnet hands out 10.92.xx.x
IP's. Regardless, I think that Jo's solution is better.
From my home:
[gijs@xiphos ~]$ nmap -p 443 netlogin.kuleuven.be
Starting Nmap 6.46 ( http://nmap.org ) at 2015-01-24 13:45 CET
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.09 seconds
So, we'll execute a HTTPS request to ensure that we're on the kotnet network.
Try the following code in a python interpreter. It works fine here :-)
import socket
def test():
print "================ KOTNET CONNECTION TEST ================"
## try to open a TCP connection on port 443 with a timeout of 1.5 second
try:
sock = socket.create_connection(("netlogin.kuleuven.be", 443), 1.5)
sock.close()
print "I could successfully connect to netlogin.kuleuven.be"
except:
print "Connection attempt to netlogin.kuleuven.be timed out. Are you on the kotnet network?"
test()
In [1]: import socket
In [2]: def test():
print "================ KOTNET CONNECTION TEST ================"
try:
sock = socket.create_connection(("netlogin.kuleuven.be", 443), 1.5)
sock.close()
print "I could successfully connect to netlogin.kuleuven.be"
except:
print "Connection attempt to netlogin.kuleuven.be timed out. Are you on the kotnet network?"
In [3]: test()
================ KOTNET CONNECTION TEST ================
Connection attempt to netlogin.kuleuven.be timed out. Are you on the kotnet network?
Nice code, I really like the lightweight socket
import.
ok,
I implemented this in the dev
branch, as linked above. I moved the functionality from tools/pinger
to browser
as it fits more cohesively I think. Moreover this allows us to override the behavior in the DummyBrowser
:-)
Should work nicely. If not we reopen this issue
When
netlogin.kuleuven.be
server is not responding, it means the user is not on a KotNet network and thereforekotnetcli
should exit gracefully with an exit code and information message (if not --quiet) to inform the user