Python-based wifi sharing tool

Source: Internet
Author: User

I didn't know that the win7 system could also be used as a wireless router. Now that I know about this, I will do it.

A wifi sharing tool written in python is not complete enough, and some features have not been done yet (Note: You need to manually set internet shared connections )......

 
 


If you don't talk about anything, paste the source code!

#-*-Coding: UTF-8 -*-
Import sys
Reload (sys)
Sys. setdefaultencoding ('utf-8 ')
Import OS
Import wx
Import ConfigParser
Myconfig = ConfigParser. ConfigParser ()
Myconfig. read ('config. ini ')
New_ssid = str (myconfig. get ('ssid ', 'myssid '))
New_passwd = str (myconfig. get ('passwd', 'mypasswd '))
New_security = str (myconfig. get ('security _ type', 'mysecurity '))
New_showpwd = str (myconfig. get ('showpwd', 'showpwd '))
New_security_dict = {'wpa2': 0, 'unauthenticated (open) ': 1}

 


Class frame (wx. Frame ):
Def _ init _ (self ):
Wx. frame. _ init _ (self, None,-1, "Wi-Fi sharing helper", size = (390,240), style = wx. CAPTION | wx. MINIMIZE_BOX | wx. CLOSE_BOX)
Self. panel = wx. Panel (self,-1)
Ssid = wx. StaticText (self. panel,-1, "Network SSID:", pos = (15, 20 ))
Self. ssid_input = wx. TextCtrl (self. panel,-1, value = new_ssid, size = (225,20), pos = (80, 20 ))
Self. ssid_input.Refresh ()
Self. ssid_input.SetMaxLength (31)
Self. ssid_input.Bind (wx. EVT_TEXT, self. ssid_evt)
Lenssid = wx. StaticText (self. panel,-1, "(1-31 characters)", pos = ))
Security = wx. StaticText (self. panel,-1, "Network security type:", pos = (15, 50 ))
Self. security = wx. ComboBox (self. panel,-1, choices = ['wpa2', 'unauthenticated (open) '], pos = ))
Self. security. Select (new_security_dict [new_security])
Self. security. Bind (wx. EVT_COMBOBOX, self. security_evt)
Self. passwd_st = wx. StaticText (self. panel,-1, "Network key:", pos = (15, 80 ))
Self. passwd = wx. TextCtrl (self. panel,-1, value = new_passwd, style = wx. TE_PASSWORD, size = (), pos = ))
Self. passwd_no = wx. TextCtrl (self. panel,-1, value = new_passwd, size = (), pos = ))
Self. passwd_no.Bind (wx. EVT_TEXT, self. passwd_no_evt)
Self. passwd. Bind (wx. EVT_TEXT, self. passwd_evt)
Self. passwd. SetMaxLength (63)
Self. lenpwd = wx. StaticText (self. panel,-1, "(8-63 characters)", pos = (, 80 ))
Self. showpwd = wx. CheckBox (self. panel,-1, "show key characters", pos = (15,110 ))
Self. showpwd. Bind (wx. EVT_CHECKBOX, self. showpwd_evt)
Self. value = wx. CheckBox (self. panel,-1, "Save this network setting", pos = (115,110 ))
Self. value. Bind (wx. EVT_CHECKBOX, self. value_evt)
Self. auto = wx. CheckBox (self. panel,-1, "automatically enable Wi-Fi sharing upon startup", pos = (235,110 ))
Self. auto. Bind (wx. EVT_CHECKBOX, self. auto_evt)
Self. start_wifi = wx. Button (self. panel,-1, "enable Wi-Fi", pos = (15,150 ))
Self. start_wifi.Bind (wx. EVT_BUTTON, self. start_wifi_evt)
Self. stop_wifi = wx. Button (self. panel,-1, "Disable Wi-Fi", pos = (120,150 ))
Self. stop_wifi.Bind (wx. EVT_BUTTON, self. stop_wifi_evt)
If myconfig. get ('windows', 'start _ on_windows ') = 'true ':
Self. auto. SetValue (True)
Else:
Self. auto. SetValue (False)
If myconfig. get ('Save _ config', 'Save _ config') = 'true ':
Self. value. SetValue (True)
Else:
Self. value. SetValue (False)
If str (self. security. GetValue () = "no authentication (open )":
Self. passwd. Hide ()
Self. passwd_st.Hide ()
Self. lenpwd. Hide ()
Self. passwd_no.Hide ()
Self. showpwd. Disable ()
If new_showpwd = "true ":
Self. passwd. Hide ()
Self. showpwd. SetValue (True)
Else:
Self. passwd_no.Hide ()
Self. showpwd. SetValue (False)
Def showpwd_evt (self, evt ):
If self. showpwd. GetValue () is True:
Self. passwd. Hide ()
Self. passwd_no.Show ()
Myconfig. set ('showpwd', 'showpwd', 'true ')
Myconfig. write (open ('config. ini ', 'w '))
Else:
Self. passwd_no.Hide ()
Self. passwd. Show ()
Myconfig. set ('showpwd', 'showpwd', 'false ')
Myconfig. write (open ('config. ini ', 'w '))
Def auto_evt (self, evt ):
If myconfig. get ('windows', 'start _ on_windows ') = 'true ':
Myconfig. set ('windows', 'start _ on_windows ', 'false ')
Myconfig. write (open ('config. ini ', 'w '))
Else:
Myconfig. set ('windows', 'start _ on_windows ', 'true ')
Myconfig. write (open ('config. ini ', 'w '))
Def value_evt (self, evt ):
If myconfig. get ('Save _ config', 'Save _ config') = 'true ':
Myconfig. set ('Save _ config', 'Save _ config', 'false ')
Myconfig. set ('ssid ', 'myssid ','')
Myconfig. set ('passwd', 'mypasswd ','')
Myconfig. set ('security _ type', 'mysecurity', 'wpa2 ')
Myconfig. write (open ('config. ini ', 'w '))
Else:
Myconfig. set ('Save _ config', 'Save _ config', 'true ')
Myconfig. set ('ssid ', 'myssid', str (self. ssid_input.GetValue ()))
Myconfig. set ('passwd', 'mypasswd', str (self. passwd. GetValue ()))
Myconfig. set ('security _ type', 'mysecurity', str (self. security. GetValue ()))
Myconfig. write (open ('config. ini ', 'w '))
Def ssid_evt (self, evt ):
Myconfig. set ('ssid ', 'myssid', str (self. ssid_input.GetValue ()))
Myconfig. write (open ('config. ini ', 'w '))
Def passwd_evt (self, evt ):
Myconfig. set ('passwd', 'mypasswd', str (self. passwd. GetValue ()))
Myconfig. write (open ('config. ini ', 'w '))
Self. passwd_no.SetValue (self. passwd. GetValue ())
Def passwd_no_evt (self, evt ):
Myconfig. set ('passwd', 'mypasswd', str (self. passwd_no.GetValue ()))
Myconfig. write (open ('config. ini ', 'w '))
Self. passwd. SetValue (self. passwd_no.GetValue ())
Def security_evt (self, evt ):
Myconfig. set ('security _ type', 'mysecurity', str (self. security. GetValue ()))
Myconfig. write (open ('config. ini ', 'w '))
If str (self. security. GetValue () = "no authentication (open )":
Self. passwd. Hide ()
Self. passwd_st.Hide ()
Self. lenpwd. Hide ()
Self. passwd_no.Hide ()
Self. showpwd. Disable ()
Else:
Self. showpwd. Enable ()
Self. passwd_st.Show ()
Self. lenpwd. Show ()
If self. showpwd. GetValue () is True:
Self. passwd_no.Show ()
Else:
Self. passwd. Show ()

Def start_wifi_evt (self, evt ):
OS. system ("net start wlansvc ")
OS. system ("netsh wlan set hostednetwork mode = allow ")
If str (self. security. GetValue () = "no authentication (open )":
Self. passwd. SetValue ("")
OS. system ("netsh wlan set hostednetwork ssid = % s key = % s" % (self. ssid_input.GetValue (), self. passwd. GetValue ()))
OS. system ("netsh wlan start hostednetwork ")
Self. start_wifi.Disable ()
Def stop_wifi_evt (self, evt ):
OS. system ("netsh wlan stop hostednetwork ")
Self. start_wifi.Enable ()



 


Class app (wx. App ):
Def OnInit (self ):
Myframe = frame ()
Myframe. Show ()
Return True
If _ name __= = "_ main __":
Myapp = app ()
Myapp. MainLoop ()

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.