用C#远程开关MW300R的无线

感觉路由器在睡觉的时候就不用开着无线了,关了还可以减少辐射(不能全关了,因为还有电脑需要有线)。苦于家里用的是水星MW300r,而且硬件以及缩水到v9.1版了,SoC还是QCA开头的,改完内存和Flash依然没有Openwrt刷,这样自然不能设定定时关闭无线了。又不想再买台可以刷的路由器,就想到如题所说的方法,刚好家里有台电脑是24小时开着(功耗很低),又是用网线连着路由器,就想着能不能在里面设定一个计划任务来定时开关MW300r的无线。

用C#编写如下程序,代码:

private static string rounterIP = System.Configuration.ConfigurationManager.AppSettings["RounterIP"];
private static string rounterUser = System.Configuration.ConfigurationManager.AppSettings["RounterUser"];
private static string rounterPasswd = System.Configuration.ConfigurationManager.AppSettings["RounterPasswd"];
 
static void Main(string[] args)
{
	try
	{
		bool wlanON = true;
		foreach (string arg in args)
		{
			if(arg.Equals("-s", StringComparison.CurrentCultureIgnoreCase))
				wlanON = false;
		}
 
		byte[] bytes = Encoding.Default.GetBytes(rounterUser + ":" + rounterPasswd);
		string base64str = Convert.ToBase64String(bytes);
 
		string url = "http://" + rounterIP + "/userRpm/WlanNetworkRpm.htm?broadcast=2&brlssid=&brlbssid=&detctwds=1&keytype=1&wepindex=1&keytext=&Save=%B1%A3+%B4%E6";
		if (wlanON)
			url += "&ap=1";
 
		HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
		req.Referer = "http://" + rounterIP + "/userRpm/WlanNetworkRpm.htm";
		req.Headers.Add(HttpRequestHeader.Authorization, "Basic " + base64str);
		req.Method = "GET";
		req.GetResponse();
		Console.WriteLine("WiFi已" + (wlanON ? "打开" : "关闭"));
	}
	catch (Exception e)
	{
		Console.Write(e.Message);
	}
	Thread.Sleep(5000);
}

注意前面三行依次是路由器IP,用户名和登录密码,可根据实际修改!编成命令行程序,后面加个-s参数是关闭无线的,不加那个参数就是打开无线,然后配置一下计划任务就OK了!

此程序在硬件版本9.1固件版本1.0.8 Build 130719下测试通过!其它固件版本可能需要重启路由器后才能生效!

转载注明:http://www.shenyaocn.com/?p=132