Form1.cs 798 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace WindowsFormsIPEndPoint
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. private void button1_Click(object sender, EventArgs e)
  20. {
  21. //实例化IPEndPoint类对象
  22. IPEndPoint IPEPoint = new IPEndPoint(IPAddress.Parse(textBox1.Text), 80);
  23. //使用IPEndPoint类对象获取终结点的IP地址和端口号
  24. label2.Text = "IP地址:" + IPEPoint.Address.ToString() + "\n端口号:" + IPEPoint.Port;
  25. }
  26. }
  27. }