| | |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Net; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | |
| | | txt_port.Focus(); |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | IPAddress.Parse(txt_ip.Text); |
| | | } |
| | | catch |
| | | { |
| | | txt_ip.Text = ""; |
| | | if (!validateIpAddress(txt_ip.Text.Trim())) { |
| | | MessageBox.Show("请输入正确的IP地址"); |
| | | txt_ip.Focus(); |
| | | return; |
| | |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | private bool validateIpAddress(string ip) |
| | | { |
| | | string pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; |
| | | return Regex.IsMatch(ip, pattern); |
| | | } |
| | | } |
| | | } |