当前位置: 首页>>代码示例>>C#>>正文


C# IPAddress.ToString方法代码示例

本文整理汇总了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));
        }
开发者ID:shmao,项目名称:corefx,代码行数:7,代码来源:GetHostEntryTest.cs

示例2: GetUnresolvedAnswer

 public static IPHostEntry GetUnresolvedAnswer(IPAddress address)
 {
     return new IPHostEntry
     {
         HostName = address.ToString(),
         Aliases = Array.Empty<string>(),
         AddressList = new IPAddress[] { address }
     };
 }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:9,代码来源:NameResolutionUtilities.cs

示例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);
                }
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:60,代码来源:Ping.Unix.cs

示例4: resolvename

 public string resolvename(IPAddress hostiptoresolve)
 {
     string tempname;
     tempname = Dns.Resolve(hostiptoresolve.ToString()).HostName.ToString();
     return tempname;
 }
开发者ID:safronovba,项目名称:MS,代码行数:6,代码来源:icmp.cs

示例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;
 }
开发者ID:safronovba,项目名称:MS,代码行数:7,代码来源:icmp.cs

示例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();
    }
开发者ID:ErykB2000,项目名称:xplproject,代码行数:14,代码来源:HalObjects.cs

示例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);
            }
    }
开发者ID:ratulmukh,项目名称:tashjik,代码行数:18,代码来源:Boxit.cs

示例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.");
            }
开发者ID:crowdy,项目名称:OpenStack-ConoHa,代码行数:19,代码来源:IPAddressDetailsConverter.cs

示例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 ();
		}
开发者ID:vargaz,项目名称:mono,代码行数:19,代码来源:Ping.cs

示例10: UnBanIP

			/// <summary>
			/// 取消指定主机的屏蔽
			/// </summary>
			/// <param name="ip"></param>
			public void UnBanIP(IPAddress ip)
			{
				if (BanedHost != null && BanedHost.Contains(ip.ToString())) BanedHost.Remove(ip.ToString());
			}
开发者ID:iraychen,项目名称:IpMsg.Net,代码行数:8,代码来源:Config.cs

示例11: IsHostInBlockList

			/// <summary>
			/// 检测一个主机是否在黑名单中
			/// </summary>
			/// <param name="ip"></param>
			/// <returns></returns>
			public bool IsHostInBlockList(IPAddress ip)
			{
				return (BanedHost != null && BanedHost.Contains(ip.ToString()));
			}
开发者ID:iraychen,项目名称:IpMsg.Net,代码行数:9,代码来源:Config.cs

示例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());
			}
开发者ID:iraychen,项目名称:IpMsg.Net,代码行数:9,代码来源:Config.cs

示例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();
        }
    }
开发者ID:Ryuho,项目名称:SharpSender,代码行数:69,代码来源:SharpSender.cs

示例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)
//.........这里部分代码省略.........
开发者ID:Ryuho,项目名称:SharpSender,代码行数:101,代码来源:SharpSender.cs

示例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);
			}
开发者ID:iraychen,项目名称:IpMsg.Net,代码行数:13,代码来源:Config.cs


注:本文中的IPAddress.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。