using System.Net;
try { IPAddress a = IPAddress.Parse(输入的IP字符串); } catch (System.Exception ex) { MessageBox.Show("输入错误:输入的IP地址无效,请重新输入。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }