zoukankan      html  css  js  c++  java
  • winform 网络部分编程 ,浏览器,域名解析,下载网址内容

    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);
            }
        }
    }
    发现自己的不足,善于利用找到的方法去扬长避短。行动起来。
  • 相关阅读:
    Swift 类的使用class
    Swift 结构体struct
    Swift 枚举enum
    Swift 元组 Tuple
    python UI自动化截图对比
    取出yaml中的字符并转换为元祖
    python 使用pyinstaller对PY文件进行exe打包
    Jenkins 浏览器打开提示离线
    pywinauto 学习笔记-利用文本框输入操作键盘
    打开文件测试的测试点
  • 原文地址:https://www.cnblogs.com/rechen/p/5113296.html
Copyright © 2011-2022 走看看