Code
using System;
using System.Collections.Generic;
using System .Net ;
using System .Net .Sockets ;
using System.Text .RegularExpressions;
namespace NetWork
{
class NetWork
{
public static void Main(string[] args)
{
//
string[] slist = {"12.123.23.4","12.23.*.56","23.34.*.*","12.23.3*.1"};
Regex rg = new Regex(@"^(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$");
// foreach (string s in slist)
// Console.WriteLine("{0}:{1}", s, rg.IsMatch(s));
Console.WriteLine("Input HostName!");
string pHostName=Console.ReadLine ();
IPHostEntry myAddress=Dns.GetHostByName(pHostName);
Console.WriteLine ("{0} IP Address is ",pHostName);
IPAddress[] myIpAddress=myAddress.AddressList;
foreach(IPAddress ip in myIpAddress)
{
Console.WriteLine (ip);
}
string pAddress=Console.ReadLine ();
do
{
if(rg.IsMatch (pAddress))
{
IPHostEntry myHostName=Dns.GetHostByAddress(pAddress);
Console.WriteLine ("{0}对应的主机名{1}:",pAddress,myHostName.HostName.ToString ());
}
else
{
Console.WriteLine ("IP 格式不对");
}
pAddress=Console.ReadLine ();
}while(!pAddress.Equals("0"));
}
}
}
using System;
using System.Collections.Generic;
using System .Net ;
using System .Net .Sockets ;
using System.Text .RegularExpressions;
namespace NetWork
{
class NetWork
{
public static void Main(string[] args)
{
//
string[] slist = {"12.123.23.4","12.23.*.56","23.34.*.*","12.23.3*.1"};
Regex rg = new Regex(@"^(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)\.(\d{1,3}|\*)$");
// foreach (string s in slist)
// Console.WriteLine("{0}:{1}", s, rg.IsMatch(s));
Console.WriteLine("Input HostName!");
string pHostName=Console.ReadLine ();
IPHostEntry myAddress=Dns.GetHostByName(pHostName);
Console.WriteLine ("{0} IP Address is ",pHostName);
IPAddress[] myIpAddress=myAddress.AddressList;
foreach(IPAddress ip in myIpAddress)
{
Console.WriteLine (ip);
}
string pAddress=Console.ReadLine ();
do
{
if(rg.IsMatch (pAddress))
{
IPHostEntry myHostName=Dns.GetHostByAddress(pAddress);
Console.WriteLine ("{0}对应的主机名{1}:",pAddress,myHostName.HostName.ToString ());
}
else
{
Console.WriteLine ("IP 格式不对");
}
pAddress=Console.ReadLine ();
}while(!pAddress.Equals("0"));
}
}
}