更改火狐主页与服务器网络检测

主程序:

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Windows.Forms;
  6 using System.IO;
  7 using System.Diagnostics;
  8 using System.Text.RegularExpressions;
  9 namespace Maintenance
 10 {
 11     public partial class frm_Main : Form
 12     {
 13         int app_count = 0;
 14         public frm_Main()
 15         {
 16             InitializeComponent();
 17         }
 18
 19         #region 火狐设置
 20         private void Firefox_Set_button_Click(object sender, EventArgs e)
 21         {
 22             //主页设置
 23             string Set_Path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Mozilla\Firefox\profiles.ini";
 24             string Path2 = "";
 25             List<string> str = new List<string>();
 26             using (StreamReader reader = File.OpenText(Set_Path))
 27             {
 28                 string line = "";
 29                 while ((line = reader.ReadLine()) != null)
 30                 {
 31                     str.Add(line);
 32                 }
 33             }
 34             string NewPath = "";
 35             if (str.Where(n => n.Equals("[Profile0]")).ToArray().Length > 0)
 36             {
 37                 string temp=str.Where(n => n.Contains("Path")).ToArray()[0];
 38                 Path2 = temp.Substring(5, temp.Length - 5);
 39                 NewPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Mozilla\Firefox\" + Path2 + @"\prefs.js";
 40             }
 41             if (str.Where(n => n.Equals("[Profile1]")).ToArray().Length > 0)
 42             {
 43                 string temp = str.Where(n => n.Contains("Path")).ToArray()[0];
 44                 Path2 = temp.Substring(5, temp.Length - 5);
 45                 NewPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Mozilla\Firefox\" + Path2 ;
 46             }
 47
 48             StringBuilder builder = new StringBuilder();
 49             using (StreamReader reader = File.OpenText(NewPath))
 50             {
 51                 string line = "";
 52                 bool flag = true;
 53                 while ((line = reader.ReadLine()) != null)
 54                 {
 55                     if (line.Contains("\"browser.startup.homepage\"")&&flag==true)
 56                     {
 57                         builder.Append("user_pref(\"browser.startup.homepage\", \""+this.HomePage_textBox.Text.Trim()+"\");\n");
 58                         flag = false;
 59                     }
 60                     else
 61                     {
 62                         builder.Append(line+"\n");
 63                     }
 64                 }
 65             }
 66             File.WriteAllText(NewPath, builder.ToString());
 67
 68             if(File.Exists(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"))
 69             {
 70                 Process pro = Process.Start(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
 71                 pro.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
 72                 pro.WaitForInputIdle(1000);
 73                 if (pro.Responding)
 74                 {
 75                     SendKeys.SendWait("{F11}");
 76                 }
 77             }
 78         }
 79         #endregion
 80
 81         #region 界面初始化
 82
 83         private void Init()
 84         {
 85             //设置主页
 86             this.HomePage_textBox.Text = System.Configuration.ConfigurationSettings.AppSettings["HomePage"];
 87         }
 88         private void frm_Main_Load(object sender, EventArgs e)
 89         {
 90             this.Init();
 91             this.app_timer.Start();
 92         }
 93         #endregion
 94
 95         #region 退出
 96         private void Exit_button_Click(object sender, EventArgs e)
 97         {
 98             Application.Exit();
 99         }
100         #endregion
101
102         private void PingServer_button_Click(object sender, EventArgs e)
103         {
104             Process p = new Process();
105             p.StartInfo.FileName = "cmd.exe";
106             p.StartInfo.UseShellExecute = false;
107             p.StartInfo.RedirectStandardInput = true;
108             p.StartInfo.RedirectStandardOutput = true;
109             p.StartInfo.RedirectStandardError = true;
110             p.StartInfo.CreateNoWindow = true;
111
112             p.Start();
113             p.StandardInput.WriteLine("ping -n " + System.Configuration.ConfigurationSettings.AppSettings["PingCount"] + " " + System.Configuration.ConfigurationSettings.AppSettings["ServerIP"]);
114             p.StandardInput.WriteLine("exit");
115             string strRst = p.StandardOutput.ReadToEnd();
116             //计数
117             int count = 0;
118             MatchCollection m1 = Regex.Matches(strRst, @"(0% loss)");
119             MatchCollection m2 = Regex.Matches(strRst, @"Destination host unreachable.");
120             MatchCollection m3 = Regex.Matches(strRst, @"Request timed out.");
121             MatchCollection m4 = Regex.Matches(strRst, @"Unknown host");
122             count = m1.Count + m2.Count + m3.Count + m4.Count;;
123
124             File.WriteAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\log.txt", strRst, Encoding.UTF8);
125             if (count >= int.Parse(System.Configuration.ConfigurationSettings.AppSettings["AlarmCount"]))
126             {
127                 Process.Start(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\log.txt");
128                 MessageBox.Show("网络不稳定,请检查!", "提示");
129             }
130             else
131             {
132                 File.Delete(System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\log.txt");
133                 MessageBox.Show("网络稳定!", "提示");
134             }
135         }
136
137         #region 检查程序关闭时间
138         private void app_timer_Tick(object sender, EventArgs e)
139         {
140             app_count++;
141             if (app_count == 60 * int.Parse(System.Configuration.ConfigurationSettings.AppSettings["AppTime"]))
142             {
143                 Application.Exit();
144             }
145         }
146         #endregion
147
148         #region 一键设置客户端
149         private void ClientSet_button_Click(object sender, EventArgs e)
150         {
151             Firefox_Set_button_Click(null, null);
152             PingServer_button_Click(null,null);
153         }
154         #endregion
155     }
156 }

配置文件:

 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <configuration>
 3   <appSettings>
 4     <add key="HomePage" value="http://www.cnblogs.com/"/>   <!--服务器主页-->
 5     <add key="ServerIP" value="192.168.1.1"/>               <!--服务器IP-->
 6     <add key="PingCount" value="100"/>                      <!--Ping服务器次数-->
 7     <add key="AlarmCount" value="5"/>                       <!--报警次数-->
 8     <add key="AppTime" value="10"/>                         <!--程序运行时间,以分钟为单位-->
 9   </appSettings>
10 </configuration>
时间: 2024-08-28 11:57:37

更改火狐主页与服务器网络检测的相关文章

udp 双机通信(服务器循环检测)2

此文摘自:http://blog.csdn.net/qinpeng100423/article/details/8980423,谢谢了 自己上一篇写的udp通信,只能运行一次,参考了这位博主的,只是把receive的方法处改为循环,这样即可实现服务器循环检测,然后接受数据和回复 受到项目要求,将文件分离,读者引用该类,实例化调用方法即可. 一. UDP协议定义 UDP协议的全称是用户数据报,在网络中它与TCP协议一样用于处理数据包.在OSI模型中,在第四层——传输层,处于IP协议的上一层.UDP

linux服务器性能检测工具nmon使用

今天介绍一款linux系统服务器性能检测的工具-nmon及nmon_analyser (生成性能报告的免费工具),亲测可用. 一.介绍 nmon 工具可以帮助在一个屏幕上显示所有重要的性能优化信息,并动态地对其进行更新.这个高效的工具可以工作于任何哑屏幕.telnet 会话.甚至拨号线路.另外,它并不会消耗大量的 CPU 周期,通常低于百分之二.在更新的计算机上,其 CPU 使用率将低于百分之一. 使用哑屏幕,在屏幕上对数据进行显示,并且每隔两秒钟对其进行更新.然而,您可以很容易地将这个时间间隔

5种服务器网络编程模型讲解(转)

作者:快课网——Jay13 原文链接:http://www.cricode.com/3510.html 本文介绍几种服务器网络编程模型.废话不多说,直接正题. 1.同步阻塞迭代模型 同步阻塞迭代模型是最简单的一种IO模型. 其核心代码如下: 1 2 3 4 5 6 7 8 bind(srvfd); listen(srvfd); for(;;){ clifd = accept(srvfd,...); //开始接受客户端来的连接 read(clifd,buf,...);       //从客户端读取

HAProxy后端web服务器状态检测

后端web服务器状态检测 HAProxy有三种状态检测方式:1.基于四层的传输端口做状态监测2.基于指定的uri做状态监测3.基于指定的URI的resquest请求头部内容做状态监测 基于四层的传输端口做状态监测 四层传输时可以基于ip或者port做监测,也可以将ip和port监测在后端服务器上的另一个地址和端口用来实现数据通道和监测通道的分离示例:1.修改配置文件 [[email protected] ~]# vim /etc/haproxy/haproxy.cfg frontend web

Linux shell脚本判断服务器网络是否可以上网

Linux shell脚本判断网络畅通 介绍 在编写shell脚本时,有的功能需要确保服务器网络是可以上网才可以往下执行,那么此时就需要有个函数来判断服务器网络状态 我们可以通过curl来访问 www.baidu.com,从而判断服务器网络状态是否可以畅通的 网络状态判断 #!/bin/bash #检测网络链接畅通 function network() { #超时时间 local timeout=1 #目标网站 local target=www.baidu.com #获取响应状态码 local

关于服务器网络编程

关于服务器网络编程,个人觉得有以下几点是要了解的: ①. tcp是一个流,所以会出现粘包现象,关于粘包以及解决可参考 http://blog.csdn.net/zhangxinrun/article/details/6721495  http://blog.csdn.net/zhangxinrun/article/details/6721495 这两篇博文. tcp的三次握手和断开连接的四次握手原理,time_wait状态,有时间的话可以再读读那本tcp/ip经典书,熟悉tcp/ip协议栈. ②

服务器网络配置

例如将服务器网络配置设置如下 IP:172.16.1.10 Mask:255.255.00 Gateway:172.16.1.1 DNS:202.0.20.106 设置如下: 先查看ip地址,此时ip地址为:172.18.12.68 输入命令cd /etc/sysconfig/network-scripts/ 第一个文件夹为默认网络地址文件夹进入修改即可 修改结果如下:此时ip地址为172.16.1.0 网关为172.15.1.1 子网掩码:255.255.255.0 修改成功!

查看Linux服务器网络状态(转)

转载自http://blog.chinaunix.net/uid-26413552-id-3202366.html 查看Linux服务器网络状态 ifconfig 用来显示所有网络接口的详细情况的,如:ip地址,子网掩码等. ethx是以太网网卡的名称. 配置文件在/etc/sysconfig/network-scripts/ifcfg-eth0中 DEVICE="eth0" HWADDR="00:0C:29:68:C0:8C" NM_CONTROLLED=&quo

Linux服务器 -- 网络篇

希望大家看完此文后,能很清楚明白你的服务器的网络情况,能很轻松的配置其网络环境.Linux服务器在装完系统,配置其网络环境是每一个system administrator的职能. 一.服务器的网络配置 在服务器的网络配置时,喜欢图形的朋友可用setup或system-config-network来配置. 网卡配置文件为/etc/sysconfig/network-scripts/ifcfg-eth0,设置完毕后直接用service network restart生效 [[email protec