zoukankan      html  css  js  c++  java
  • 网络编程--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();
    
            }
    
    
        }
    }
    

      

     

  • 相关阅读:
    list接口如何使用
    分页导航jsp
    jstl遍历list的jsp
    sql分页查询
    sql计算总页数
    类和对象,类定义了对象的特征和行为。属性,方法。
    编写一个带有main函数的类,调用上面的汽车类,实例化奔驰、大众、丰田等不同品牌和型号,模拟开车过程:启动、加速、转弯、刹车、息火,实时显示速度。
    java编写一个汽车类,有属性:品牌、型号、排量、速度,有方法:启动、加速、转弯、刹车、息火
    jenkins 集成 pytest + allure
    jenkins环境安装(windows)
  • 原文地址:https://www.cnblogs.com/my-cat/p/7228645.html
Copyright © 2011-2022 走看看