<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    實現簡單的 hosts 添加和刪除工具

     1using System;
     2using System.Collections.Generic;
     3using System.ComponentModel;
     4using System.Data;
     5using System.Drawing;
     6using System.Linq;
     7using System.Text;
     8using System.Windows.Forms;
     9using System.IO;
    10
    11namespace Google.le
    12{
    13    public partial class Form1 : Form
    14    {
    15        public Form1()
    16        {
    17            InitializeComponent();
    18        }

    19        /// <summary>
    20        /// 按鈕事件,檢查hosts 中是否有 相關的條目
    21        /// </summary>
    22        /// <param name="sender"></param>
    23        /// <param name="e"></param>

    24        private void button1_Click(object sender, EventArgs e)
    25        {
    26            string fileName = @"C:\Windows\System32\drivers\etc\hosts";
    27            if (File.Exists(fileName))
    28            {
    29                MessageBox.Show("file exists");
    30             //讀文件stream
    31                StreamReader stream = null;
    32               //保存文件定義的字節流  
    33                StreamWriter streamWriter = null;
    34                List <string>ls = new List<string>();
    35
    36                try
    37                {
    38                    //打開hosts
    39                    stream = new StreamReader(fileName);
    40                    // a 標記是否有相關條目
    41                    bool a = false;
    42                    string strtemp="";
    43                    string temp;
    44                    while ((temp=stream.ReadLine())!=null{
    45                        
    46                       //相關條目名稱 這里以Goog。le為例
    47                        if (temp.StartsWith("#Goog.le")) {
    48                            a = true;
    49                            stream.ReadLine();
    50                            stream.ReadLine();
    51                        }
    else {
    52                           
    53                         strtemp+=temp+Environment.NewLine;
    54                        }

    55
    56                    }

    57
    58                    if (a) {
    59                        MessageBox.Show("刪除完畢");
    60                    }

    61                    else {
    62                        strtemp += "#Goog.le"+ Environment.NewLine+"203.208.37.99 goog.le"+Environment.NewLine+"203.208.37.99 webcache.googleusercontent.com"+Environment.NewLine;
    63                       
    64                        
    65                        MessageBox.Show("已經添加");
    66                        
    67                    }

    68                    richTextBox1.Text = strtemp;
    69                    stream.Close();
    70                    streamWriter = new StreamWriter(fileName);
    71                    
    72                    streamWriter.Write(strtemp);
    73                    streamWriter.Flush();
    74                    streamWriter.Close();
    75                }

    76                catch (IOException){
    77                
    78                }

    79
    80            }

    81            else
    82            {
    83                MessageBox.Show("file not found");
    84            }

    85        }

    86    }

    87}

    88
    關于用程序修改 hosts 這里做了簡單的版本。這里用一種取巧的方式,并沒有用正則表達式匹配。(雖說正則表達式的效果會好一點)以后有機會做一個正則表達式的。這個小程序正好是我的一個朋友需要的小工具。臨時湊合了一個。

    ----------------以下是hosts的相關格式------此程序只適用于以下格式的hosts

    # Copyright (c) 1993-1999 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    #      102.54.94.97     rhino.acme.com          # source server
    #       38.25.63.10     x.acme.com              # x client host

    #127.0.0.1         localhost                              

     218.11.132.81     f1.xiami.net                             #f3.xiami.net
    #Goog.le
    203.208.37.99 goog.le
    203.208.37.99 webcache.googleusercontent.com

    ——————————————————————————————————————————————————————————
    最后貼上一個我朋友的博客http://sneezry.com/ 里面有相關google的中國穩定的訪問方式一文值得推薦

    posted on 2011-02-21 00:01 scorpio小蝎 閱讀(1068) 評論(0)  編輯  收藏 所屬分類: C#

    <2011年2月>
    303112345
    6789101112
    13141516171819
    20212223242526
    272812345
    6789101112

    導航

    統計

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    友情鏈接

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产精品亚洲综合网站| 亚洲国产精品嫩草影院| 大妹子影视剧在线观看全集免费 | 国产黄色片在线免费观看| 亚洲av乱码一区二区三区| 久久久久久免费视频| 亚洲国产中文在线二区三区免| 亚洲免费福利视频| 亚洲综合偷自成人网第页色| 国产成人免费爽爽爽视频| 亚洲AV综合永久无码精品天堂| 国产免费私拍一区二区三区| 日韩在线视频免费| 亚洲精品成人片在线观看精品字幕| 97人妻精品全国免费视频| 久久亚洲精品无码aⅴ大香| 99爱在线精品免费观看| 亚洲国产综合AV在线观看| 亚洲成av人在片观看| 三年片免费观看大全国语| 亚洲日本中文字幕| 女人被男人桶得好爽免费视频| 国产亚洲精品第一综合| 亚洲中文字幕在线乱码| 5g影院5g天天爽永久免费影院| 亚洲一区二区三区四区视频| 可以免费观看的一级毛片| 久久国产精品成人免费| 国产日本亚洲一区二区三区| 国产嫩草影院精品免费网址| 中文在线观看免费网站| 亚洲熟妇无码爱v在线观看| 啊灬啊灬别停啊灬用力啊免费看| 两个人看的www高清免费观看| 久久精品亚洲AV久久久无码 | 亚洲av乱码中文一区二区三区| 亚洲AⅤ视频一区二区三区| 免费成人在线电影| 亚洲中文无码永久免| 亚洲精品无码永久中文字幕| 在线观看特色大片免费视频|