本文整理汇总了C#中IPAddress.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IPAddress.ToString方法的具体用法?C# IPAddress.ToString怎么用?C# IPAddress.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPAddress
的用法示例。
在下文中一共展示了IPAddress.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dns_GetHostEntryAsync_AnyIPAddress_Fail
public async Task Dns_GetHostEntryAsync_AnyIPAddress_Fail(IPAddress address)
{
string addressString = address.ToString();
await Assert.ThrowsAsync<ArgumentException>(() => Dns.GetHostEntryAsync(address));
await Assert.ThrowsAsync<ArgumentException>(() => Dns.GetHostEntryAsync(addressString));
}
示例2: GetUnresolvedAnswer
public static IPHostEntry GetUnresolvedAnswer(IPAddress address)
{
return new IPHostEntry
{
HostName = address.ToString(),
Aliases = Array.Empty<string>(),
AddressList = new IPAddress[] { address }
};
}
示例3: SendWithPingUtility
private async Task<PingReply> SendWithPingUtility(IPAddress address, byte[] buffer, int timeout, PingOptions options)
{
bool isIpv4 = address.AddressFamily == AddressFamily.InterNetwork;
string pingExecutable = isIpv4 ? UnixCommandLinePing.Ping4UtilityPath : UnixCommandLinePing.Ping6UtilityPath;
if (pingExecutable == null)
{
throw new PlatformNotSupportedException(SR.net_ping_utility_not_found);
}
string processArgs = UnixCommandLinePing.ConstructCommandLine(buffer.Length, address.ToString(), isIpv4);
ProcessStartInfo psi = new ProcessStartInfo(pingExecutable, processArgs);
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
Process p = new Process() { StartInfo = psi };
var processCompletion = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
p.EnableRaisingEvents = true;
p.Exited += (s, e) => processCompletion.SetResult(true);
p.Start();
var cts = new CancellationTokenSource();
Task timeoutTask = Task.Delay(timeout, cts.Token);
Task finished = await Task.WhenAny(processCompletion.Task, timeoutTask).ConfigureAwait(false);
if (finished == timeoutTask && !p.HasExited)
{
// Try to kill the ping process if it didn't return. If it is already in the process of exiting, a Win32Exception will be thrown.
try
{
p.Kill();
}
catch (Win32Exception) { }
return CreateTimedOutPingReply();
}
else
{
cts.Cancel();
if (p.ExitCode != 0)
{
// This means no reply was received, although transmission may have been successful.
return CreateTimedOutPingReply();
}
try
{
string output = await p.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
long rtt = UnixCommandLinePing.ParseRoundTripTime(output);
return new PingReply(
address,
null, // Ping utility cannot accomodate these, return null to indicate they were ignored.
IPStatus.Success,
rtt,
Array.Empty<byte>()); // Ping utility doesn't deliver this info.
}
catch (Exception)
{
// If the standard output cannot be successfully parsed, throw a generic PingException.
throw new PingException(SR.net_ping);
}
}
}
示例4: resolvename
public string resolvename(IPAddress hostiptoresolve)
{
string tempname;
tempname = Dns.Resolve(hostiptoresolve.ToString()).HostName.ToString();
return tempname;
}
示例5: resolveip
public string resolveip(IPAddress hostnametoresolve)
{
string tempip = "";
try { tempip = Dns.Resolve(hostnametoresolve.ToString()).AddressList[0].ToString(); }
catch (Exception ex) { tempip = ex.Message; }
return tempip;
}
示例6: Sys
string SETTINGS_XPLHALSERVER = "localhost"; //default to localhost, but set when a client connects
#endregion Fields
#region Constructors
/// <summary>
/// </summary>
/// <param name="HalIPAddress"></param>
/// <exclude/>
public Sys(IPAddress HalIPAddress)
{
SETTINGS_XPLHALSERVER = HalIPAddress.ToString();
}
示例7: forkClientProcesses
static void forkClientProcesses()
{
Process process;
int portNo = 2340;
for(int i=0; i<5; i++)
{
byte[] byteIP = getRandomByteIP();
IPAddress IP = new IPAddress(byteIP);
String strIP = Encoding.ASCII.GetString(byteIP);
Console.WriteLine("{0} \n {1}", strIP, IP.ToString());
process = Process.Start("..\\..\\..\\TashjikClient\\bin\\Debug\\TashjikClient.exe", IP.ToString() + " " + Convert.ToString(portNo));
registry.Add(IP.ToString(), new Triplet(process, Convert.ToInt16(Convert.ToString(portNo)), null));
//registry.Add(IP.ToString(), new Triplet(process, portNo, null));
portNo++;
//Thread.Sleep(15000);
}
}
示例8: AddressDetails
/// <summary>
/// Initializes a new instance of the <see cref="AddressDetails"/> class
/// using the given IP address.
/// </summary>
/// <param name="address">The IP address.</param>
/// <exception cref="ArgumentNullException">If <paramref name="address"/> is <see langword="null"/>.</exception>
public AddressDetails(IPAddress address)
{
if (address == null)
throw new ArgumentNullException("address");
Address = address.ToString();
if (Address.Contains("."))
Version = "4";
else if (Address.Contains(":"))
Version = "6";
else
throw new ArgumentException("The specified address family is not supported.");
}
示例9: BuildPingArgs
private string BuildPingArgs (IPAddress address, int timeout, PingOptions options)
{
CultureInfo culture = CultureInfo.InvariantCulture;
StringBuilder args = new StringBuilder ();
uint t = Convert.ToUInt32 (Math.Floor ((timeout + 1000) / 1000.0));
bool is_mac = Platform.IsMacOS;
if (!is_mac)
args.AppendFormat (culture, "-q -n -c {0} -w {1} -t {2} -M ", DefaultCount, t, options.Ttl);
else
args.AppendFormat (culture, "-q -n -c {0} -t {1} -o -m {2} ", DefaultCount, t, options.Ttl);
if (!is_mac)
args.Append (options.DontFragment ? "do " : "dont ");
else if (options.DontFragment)
args.Append ("-D ");
args.Append (address.ToString ());
return args.ToString ();
}
示例10: UnBanIP
/// <summary>
/// 取消指定主机的屏蔽
/// </summary>
/// <param name="ip"></param>
public void UnBanIP(IPAddress ip)
{
if (BanedHost != null && BanedHost.Contains(ip.ToString())) BanedHost.Remove(ip.ToString());
}
示例11: IsHostInBlockList
/// <summary>
/// 检测一个主机是否在黑名单中
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public bool IsHostInBlockList(IPAddress ip)
{
return (BanedHost != null && BanedHost.Contains(ip.ToString()));
}
示例12: BanHost
/// <summary>
/// 加入一个主机到黑名单
/// </summary>
/// <param name="ip"></param>
public void BanHost(IPAddress ip)
{
if (BanedHost == null) BanedHost = new List<string>();
if (!BanedHost.Contains(ip.ToString())) BanedHost.Add(ip.ToString());
}
示例13: UpdateDevInfo
public void UpdateDevInfo(ICaptureDevice dev)
{
// if we are sending packet to all adapters
if (dev == null)
{
if (sIP == null)
{
sIP = IPAddress.Parse("255.255.255.255");
Console.WriteLine("Set sIP to: " + sIP.ToString());
}
if (dIP == null)
{
dIP = IPAddress.Parse("255.255.255.255");
Console.WriteLine("Set dIP to: " + dIP.ToString());
}
if (sMAC == null)
{
sMAC = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");
Console.WriteLine("Set sMAC to: " + sMAC.ToString());
}
if (dMAC == null)
{
dMAC = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");
Console.WriteLine("Set dMAC to: " + dMAC.ToString());
}
}
// if we picked an actual adapter
else
{
dev.Open();
// if source address is not defined, fill out the sIP
List<IPAddress> ipAddresses = Utility.GetIPAddress(dev);
foreach (IPAddress add in ipAddresses)
{
if (sIP == null && dIP != null)
{
if (dIP.ToString().Contains(".") && add.ToString().Contains("."))
{
sIP = add;
Console.WriteLine("Set sIP to: " + add.ToString());
}
else if (dIP.ToString().Contains(":") && add.ToString().Contains(":"))
{
sIP = add;
Console.WriteLine("Set sIP to: " + add.ToString());
}
}
}
if (sIP == null)
{
Console.WriteLine("The chosen adapter did not have a valid address");
Environment.Exit(1);
}
//fill out source mac if it is null
if (sMAC == null)
{
sMAC = dev.MacAddress;
Console.WriteLine("Set sMAC to: " + sMAC.ToString());
}
if (dMAC == null)
{
dMAC = PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF");
Console.WriteLine("Set dMAC to: " + dMAC.ToString());
}
dev.Close();
}
}
示例14: Param
//constructor, reads in the args
public Param(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
string curStr = args[i];
try
{
if (String.Compare(curStr, "-adapter", true) == 0)
{
string nextStr = args[++i];
adapter = nextStr;
Console.WriteLine("Read in adapter as: " + adapter);
}
else if (String.Compare(curStr, "-v6EH", true) == 0)
{
string nextStr = args[++i];
string[] tempEHArray = nextStr.Split(',');
//ExtentionHeader =
int[] tempInt = Array.ConvertAll(tempEHArray, int.Parse);
foreach (int curInt in tempInt)
{
ExtentionHeader.Add((IPProtocolType)curInt);
}
packetType = PacketType.IP;
IPProtocol = IPProtocolType.IPV6;
Console.WriteLine("Read in -v6EH as: " + string.Join(",", tempEHArray));
Console.WriteLine("Setting packetType as: " + packetType.ToString());
Console.WriteLine("Setting IPProtocol as: " + IPProtocol.ToString());
}
else if (String.Compare(curStr, "-dMAC", true) == 0)
{
string nextStr = args[++i];
nextStr = nextStr.Replace(':', '-').ToUpper();
dMAC = PhysicalAddress.Parse(nextStr);
Console.WriteLine("Read in dMAC as: " + dMAC.ToString());
}
else if (String.Compare(curStr, "-sMAC", true) == 0)
{
string nextStr = args[++i];
nextStr = nextStr.Replace(':', '-').ToUpper();
sMAC = PhysicalAddress.Parse(nextStr);
Console.WriteLine("Read in sMAC as: " + sMAC.ToString());
}
else if (String.Compare(curStr, "-dIP", true) == 0)
{
string nextStr = args[++i];
dIP = IPAddress.Parse(nextStr);
Console.WriteLine("Read in dIP as: " + dIP.ToString());
}
else if (String.Compare(curStr, "-sIP", true) == 0)
{
string nextStr = args[++i];
sIP = IPAddress.Parse(nextStr);
Console.WriteLine("Read in sIP as: " + sIP.ToString());
}
else if (String.Compare(curStr, "-IP", true) == 0)
{
string nextStr = args[++i];
packetType = PacketType.IP;
if (nextStr.StartsWith("0x"))
{
IPProtocol = (IPProtocolType)Convert.ToInt32(nextStr, 16);
}
else
{
IPProtocol = (IPProtocolType)Convert.ToInt32(nextStr);
}
Console.WriteLine("Read in IP as: " + IPProtocol.ToString());
}
else if (String.Compare(curStr, "-EtherType", true) == 0)
{
string nextStr = args[++i];
packetType = PacketType.EtherType;
if (nextStr.StartsWith("0x"))
{
EtherTypeProtocol = (EthernetPacketType)Convert.ToInt32(nextStr, 16);
}
else
{
EtherTypeProtocol = (EthernetPacketType)Convert.ToInt32(nextStr);
}
Console.WriteLine("Read in EtherType as: " + EtherTypeProtocol.ToString());
}
else if (String.Compare(curStr, "-sPort", true) == 0)
{
string nextStr = args[++i];
sPort = (ushort)Int16.Parse(nextStr);
Console.WriteLine("Read in sPort as: " + sPort.ToString());
}
else if (String.Compare(curStr, "-dPort", true) == 0)
{
string nextStr = args[++i];
dPort = (ushort)Int16.Parse(nextStr);
Console.WriteLine("Read in dPort as: " + dPort.ToString());
}
else if (String.Compare(curStr, "-type", true) == 0)
//.........这里部分代码省略.........
示例15: AddHostToDialList
/// <summary>
/// 将主机添加到拨号列表
/// </summary>
/// <param name="address"></param>
public void AddHostToDialList(IPAddress address)
{
string ip = address.ToString();
if (KeepedHostList.Contains(ip)) return;
KeepedHostList.Add(ip);
KeepedHostList_Addr.Add(address);
}