using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using System.Net.Sockets; using System.IO; using System.Collections.Specialized; namespace myone { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } //域名解析 private void button1_Click(object sender, EventArgs e) { if(txtUrl.Text!=string.Empty) { IPHostEntry host = Dns.GetHostEntry(txtUrl.Text);//獲取url的主機名 foreach (IPAddress add in host.AddressList)//主機名的ip地址列表地址 { long ip = add.Address;//主機名的ip listBox1.Items.Add(add.ToString());//加地址 255.255.255.255格式 listBox1.Items.Add(ip.ToString());//加ip long 格式 } textName.Text = host.HostName;//主機名(域名代理的狀況) textBroad.Text = IPAddress.Broadcast.ToString();//廣播地址 } else { MessageBox.Show("請輸入網址!", "錯誤提示"); } } private void textBox2_TextChanged(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox3_TextChanged(object sender, EventArgs e) { } //下載數據 private void button3_Click(object sender, EventArgs e) { WebClient clent = new WebClient();// Stream s = clent.OpenRead(textBox1.Text);//url 必須是http://www.baidu.com http://www.google.com.hk StreamReader reader = new StreamReader(s);//讀 richTextBox1.Text = reader.ReadToEnd();//顯示 reader.Close(); s.Close(); } //Header private void button4_Click(object sender, EventArgs e) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(textBox1.Text); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); NameValueCollection headers = res.Headers; foreach(string name in headers) { listBox1.Items.Add(name + "-----" + headers[name]); } } //鏈接到 Navigate航行,跳轉 private void button5_Click(object sender, EventArgs e) { textBox1.Text = "http://www.google.com.hk"; webBrowser1.Navigate(textBox1.Text, false); } } }