Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

wifi disconnect? #31

Closed
shunfan opened this issue Mar 1, 2014 · 7 comments
Closed

wifi disconnect? #31

shunfan opened this issue Mar 1, 2014 · 7 comments

Comments

@shunfan
Copy link

shunfan commented Mar 1, 2014

wifi now can only connect to a wifi, how about disconnecting from a wifi?

@rockymeza
Copy link
Owner

A disconnect command would be great. I'm willing to accept a pull request for one, but I'm not sure what the best solution is. A naïve disconnect method would just run /sbin/ifdown wlan0 (where wlan0 is the interface), but unfortunately, this turns the interface off and breaks scanning. So we would need something that could disassociate from an Access Point while still keeping the interface up.

This definitely is possible, but I don't know how to do it. If you can write a disconnect command that can disconnect without taking down the interface, I would merge it.

At some point, I think it would be cool to be able do this from the Connection object too.

scheme = Scheme.find('wlan0', 'home')
connection = scheme.activate()
# ...
connection.deactivate()

@ramnes
Copy link
Contributor

ramnes commented Apr 3, 2014

dhclient -r wlan0 could do the trick.

@rockymeza
Copy link
Owner

Hey @ramnes,

Thanks! I will try to get to this after I come back from PyCon. I'm going to have a very busy month though, so I can't promise very much.

@rockymeza
Copy link
Owner

Hi @ramnes,

I tried running dhclient -r wlan0, but it didn't seem to do anything, I'm still connected.

@ramnes
Copy link
Contributor

ramnes commented Apr 14, 2014

According to man dhclient:

-r     Release  the  current lease and stop the running DHCP client as
       previously recorded in the PID file.  When shutdown via this method
       dhclient-script(8) will be executed with the specific reason for calling
       the script set.  The client normally doesn't release the current lease
       as this is not required by the DHCP protocol but some cable ISPs
       require their clients to notify  the  server if they wish to release an
       assigned IP address.

I tried here and I could not send nor receive any packet after it.

@Jonnycake
Copy link

I think the reason that the dhclient -r wlan0 command isn't working for you @rockymeza is because you have NetworkManager (or some other network management daemon) running. Run ps -Af | grep NetworkManager and you should see it. Depending on how new your install is you will either have to run /etc/init.d/network-manager stop or initctl stop network-manager (both require root). You can then use wifi connect and then the dhclient command should work. If I get a chance I'll fork and submit a pull request to implement the deactivate() function and disconnect comand.

@rockymeza
Copy link
Owner

Moving conversation to #58.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants