windows command enumeration wifi, wifi connection

enumerate

netsh wlan show all | findstr "^\s*SSID"

netsh wlan show all show all network connections, findstr filter

 

connection

netsh wlan connect name="tplink-4jt454ktj"
多网卡的情况下指定用那块网卡链接
(普通pc只能连接2.4G赫兹的wifi,外接一个无线网卡可以连接上5G赫兹平频率的wifi,而网卡也就多了一个)
netsh wlan connect name="tplink-4jt454ktj" interface="WLAN 2"

Need to manually connect once, and saved passwords, network access if a local running scripts, determine the network connection exception can invoke this command automatically reconnect

 

python examples:

import requests
import json
import time
import sys
import os

wifiName = "tplink-4jt454ktj"

class convertWork:
	def __init__(self):
		self.data = []
		
	def connectWifi(self):
		os.system("netsh wlan connect name=\"%s\"" % wifiName)
		
	def getFiles(self, url, postData):
		
		try:
		
			response = requests.post(url, data=postData)
			
			data = json.loads(response.content)
					
			if data['errorCode'] != 0:
				print (time.strftime("%Y-%m-%d %H:%M:%S"), url, 'failed')
			
			return data
		except Exception as e:
			print (time.strftime("%Y-%m-%d %H:%M:%S"), "getFiles get except ", e)
			self.connectWifi()
			return {}

if __name__ == "__main__":
	
	if len(sys.argv) > 1 and re.match('(http|https)://.*\.com$', sys.argv[1], re.I):
		print ("change host name to", sys.argv[1])
		hostName = sys.argv[1]

	print (time.strftime("%Y-%m-%d %H:%M:%S"), "begin", hostName)
    #do something you want

Needs while executing an infinite loop, we often encounter situations wifi off, windows may not automatically reconnect, if they do not save their own procedures, follow-up can not hold up

Published 275 original articles · won praise 46 · views 280 000 +

Guess you like

Origin blog.csdn.net/youyudexiaowangzi/article/details/96476704