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);
            }
        }
    }
    发现自己的不足,善于利用找到的方法去扬长避短。行动起来。
  • 相关阅读:
    安装Bind到CentOS(YUM)
    安装Ansible到CentOS(YUM)
    安装AB到CentOS(YUM)
    安装APACHE到CentOS(YUM)
    07 Spring Cloud Eureka是什么?
    06 Spring Boot Starter的介绍及使用
    05 Spring Boot项目搭建步骤(超详细)
    04 Spring Cloud开发环境的准备和Lombok安装步骤
    03 Spring Cloud和Dubbo的区别及各自的优缺点
    02 Spring Cloud 模块介绍
  • 原文地址:https://www.cnblogs.com/rechen/p/5113296.html
Copyright © 2011-2022 走看看