• 网络编程--System.Net


    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;
    
    namespace dns类
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                label5.Text = string.Empty;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if(textBox1.Text == string.Empty)
                {
                    MessageBox.Show("请输入IP地址");
                }
                else
                {
                    textBox2.Text = string.Empty;
                    textBox3.Text = string.Empty;
                    textBox4.Text = string.Empty;
                    
                    IPAddress[] ips = Dns.GetHostAddresses(textBox1.Text);
                    foreach(IPAddress ip in ips)
                    {
                        textBox2.Text = ip.ToString();
    
                        label5.Text += "网际协议地址:" + ip.Address + "
    Ip地址的地址族:" + ip.AddressFamily.ToString() + "
    是否是IPv6连接本地地址:" + ip.IsIPv6LinkLocal;
    
                    }
                    textBox3.Text = Dns.GetHostName();
                   // textBox4.Text = Dns.GetHostByName(Dns.GetHostName()).HostName;
                }
            }
    
            private void label4_Click(object sender, EventArgs e)
            {
    
            }
    
    
        }
    }
    

     

    WebRequest 和 WebResponse类的使用

    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.IO;
    
    namespace dns类
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                richTextBox1.Text = string.Empty;
                //创建WebRequest对象
                WebRequest webreq = WebRequest.Create(textBox1.Text);
                //设置用于对Internet资源请求进行身份验证的网络凭证
                webreq.Credentials = CredentialCache.DefaultCredentials;
               
                //调用WebRequest对象的各种属性获取WebRequest请求的相关信息
                richTextBox1.Text += "请求数据内容长度:" + webreq.ContentLength;
                richTextBox1.Text += "
    该请求的协议方法:" + webreq.Method;
                richTextBox1.Text += "
    访问Internet的网络代理:" + webreq.Proxy;
                richTextBox1.Text += "
    Internet URI:" + webreq.RequestUri;
                richTextBox1.Text += "
    超时:" + webreq.Timeout;
    
                //创建WebResponse对象
                WebResponse webres = webreq.GetResponse();
                richTextBox1.Text += "
    相应请求的URI" + webres.ResponseUri;
                //创建StreamReader流读取对象
                Stream stream = webres.GetResponseStream();
                StreamReader sreader = new StreamReader(stream);
                richTextBox1.Text += "
    " + sreader.ReadToEnd();
                sreader.Close();
                stream.Close();
                webres.Close();
    
            }
    
    
        }
    }
    

      

     

  • 相关阅读:
    php 高精度计算函数
    CSS 文本溢出显示省略号样式
    Vue import、export及export default示例详解,附带如何实现全局调用
    利用高德API获取最新的省市区数据
    TP5 基类验证器
    php 两种递归方法
    新建PO類型ZFA的固定資產時灰掉 GR Non-Valuated
    MRP 參數設置
    info record
    kill procedure in os level
  • 原文地址:https://www.cnblogs.com/my-cat/p/7228645.html
Copyright © 2020-2023  润新知