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


C# IPAddress.ToString方法代码示例

本文整理汇总了C#中System.Net.IPAddress.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IPAddress.ToString方法的具体用法?C# IPAddress.ToString怎么用?C# IPAddress.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.IPAddress的用法示例。


在下文中一共展示了IPAddress.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: tcpClosed

        protected override void tcpClosed(IPAddress ip, int port)
        {
            for(LinkedListNode<IPEndPoint> it = clientIPEndPoints.First; it != null; it = it.Next)
            {
                if(it.Value.Address.ToString() == ip.ToString())
                {
                    clientIPEndPoints.Remove(it);
                    break;
                }
            }

            for(LinkedListNode<TcpClient> it = tcpClients.First; it != null; it = it.Next)
            {
                IPEndPoint iep = (IPEndPoint)it.Value.Client.RemoteEndPoint;
                if(iep.Address.ToString() == ip.ToString())
                {
                    tcpClients.Remove(it);
                    break;
                }
            }

            for (LinkedListNode<IPAddress> it = clientIPAdresses.First; it != null; it = it.Next)
            {
                if (it.Value.ToString() == ip.ToString())
                {
                    clientIPAdresses.Remove(it);
                    break;
                }
            }

            recyclePort(port);

            label1.Text = clientIPEndPoints.Count().ToString() + " Client(s) Online";
        }
开发者ID:864668723,项目名称:128,代码行数:34,代码来源:Server.cs

示例2: Main

 public static int Main()
 {
     IPAddress
     testadd
     =
     IPAddress.Parse
     ("127.0.0.1");
     Console.WriteLine("address is "
     +
     testadd.Address.ToString
     ("X"));
     if
     (testadd.Address
     !=
     0x0100007f)
     return
     1;
     IPAddress
     hostadd
     =
     new
     IPAddress(0x0100007f);
     Console.WriteLine("address is "
     +
     hostadd.ToString());
     if
     (hostadd.ToString()
     !=
     "127.0.0.1")
     return
     1;
     return
     0;
 }
开发者ID:robertmichaelwalsh,项目名称:CSharpFrontEnd,代码行数:34,代码来源:ipaddress.cs

示例3: Connect

        public static void Connect(Loop loop, IPAddress ipAddress, int port, Action<Exception, Tcp> callback)
        {
            Ensure.ArgumentNotNull(loop, "loop");
            Ensure.ArgumentNotNull(ipAddress, "ipAddress");
            Ensure.ArgumentNotNull(callback, "callback");

            ConnectRequest cpr = new ConnectRequest();
            Tcp socket = new Tcp(loop);

            cpr.Callback = (status, cpr2) => {
                if (status == 0) {
                    callback(null, socket);
                } else {
                    socket.Close();
                    callback(Ensure.Success(loop), null);
                }
            };

            int r;
            if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
                r = uv_tcp_connect(cpr.Handle, socket.handle, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
            } else {
                r = uv_tcp_connect6(cpr.Handle, socket.handle, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
            }
            Ensure.Success(r, loop);
        }
开发者ID:carlokok,项目名称:LibuvSharp,代码行数:26,代码来源:Tcp.cs

示例4: execute

        /// <summary>
        /// Actual command logic
        /// </summary>
        /// <param name="source">The user who triggered the command.</param>
        /// <param name="channel">The channel the command was triggered in.</param>
        /// <param name="args">The arguments to the command.</param>
        /// <returns></returns>
        protected override CommandResponseHandler execute(User source, string channel, string[] args)
        {
            if (args[0].Length != 8)
                return null;

            byte[] ip = new byte[4];
            ip[0] = Convert.ToByte(args[0].Substring(0, 2), 16);
            ip[1] = Convert.ToByte(args[0].Substring(2, 2), 16);
            ip[2] = Convert.ToByte(args[0].Substring(4, 2), 16);
            ip[3] = Convert.ToByte(args[0].Substring(6, 2), 16);

            IPAddress ipAddr = new IPAddress(ip);

            string hostname = "";
            try
            {
                hostname = Dns.GetHostEntry(ipAddr).HostName;
            }
            catch (SocketException)
            {
            }
            if (hostname != string.Empty)
            {
                string[] messageargs = {args[0], ipAddr.ToString(), hostname};
                return new CommandResponseHandler(new Message().get("hexDecodeResult", messageargs));
            }
            else
            {
                string[] messageargs = {args[0], ipAddr.ToString()};
                return
                    new CommandResponseHandler(new Message().get("hexDecodeResultNoResolve",
                                                                                    messageargs));
            }
        }
开发者ID:joegazz84,项目名称:helpmebot,代码行数:41,代码来源:Decode.cs

示例5: Get

 public IPBanInfo Get( IPAddress address ) {
     lock( locker ) {
         if( bans.ContainsKey( address.ToString() ) ) {
             return bans[address.ToString()];
         } else {
             return null;
         }
     }
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:9,代码来源:IPBanList.cs

示例6: AddServer

        public void AddServer(IPAddress ip)
        {
            foreach (var m in MenuEntries)
                if (m.Text == ip.ToString())
                    return;

            MenuEntry server = new MenuEntry(ip.ToString());
            server.Selected += ServerMenuEntrySelected;
            MenuEntries.Add(server);
        }
开发者ID:sinhpham,项目名称:tanka,代码行数:10,代码来源:ClientMenuScreen.cs

示例7: UpdateWithUserIp

 private void UpdateWithUserIp(string name, IPAddress ip)
 {
   BannedUser b;
   if (GetByIp(ip.ToString(), out b)) if (!b.nickNames.Contains(name)) b.nickNames.Add(name);
   if (GetByName(name, out b)) if (ip != IPAddress.None && !b.ipAddresses.Contains(ip.ToString())) b.ipAddresses.Add(ip.ToString());
   if (b != null) {
     if (b.Expired) Items.Remove(b);
     Save();
   }
 }
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:10,代码来源:BanList.cs

示例8: Log

 public void Log(String username, IPAddress addr)
 {
     String baseDirecotry = Directory.GetCurrentDirectory();
     AppendPath(ref baseDirecotry, "Logs");
     AppendPath(ref baseDirecotry, "IpLogs");
     String generalLog = Path.Combine(baseDirecotry, "ip.log");
     String userLog = Path.Combine(baseDirecotry, String.Format("{0}.log", username));
     using (StreamWriter sw = new StreamWriter(generalLog, true))
         sw.WriteLine("Account: " + username + " ha loggato con ip " + addr.ToString() + " in Data: " + DateTime.Now);
     using (StreamWriter sw = new StreamWriter(userLog, true))
         sw.WriteLine("Account: " + username + " ha loggato con ip " + addr.ToString() + " in Data: " + DateTime.Now);
 }
开发者ID:Shadow649,项目名称:SpeedHackDetector,代码行数:12,代码来源:IpStorage.cs

示例9: Update

        public override void Update(HostConfig HC, IPAddress ipAddress)
        {
            if (HC == null) throw new ArgumentNullException("HC");
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");

            using (RMWebClient WC = new RMWebClient())
            {
                WC.ContentType = "application/xml";
                WC.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(HC.Username + ":" + HC.Password.GetPlainText()));
                WC.Headers["Accept"] = "application/xml";
                WC.UseDefaultCredentials = false;

                try
                {
                    string Url = "https://pointhq.com";
                    Url += "/zones/" + HC.ProviderSpecificSettings[HostConfig.POINT_ZONE_ID];
                    Url += "/records/" + HC.ProviderSpecificSettings[HostConfig.POINT_RECORD_ID];

                    string ResponseText = WC.UploadString(Url, "PUT", "<zone-record><data>" + ipAddress.ToString() + "</data><ttl type=\"integer\">60</ttl></zone-record>").Trim();
                    if (!ResponseText.Contains(ipAddress.ToString()))
                    {
                        HC.Disabled = true;
                        HC.DisabledReason = "Reason not known.";
                        HC.Save();

                        Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                    }
                }
                catch (WebException wex)
                {
                    HC.Disabled = true;
                    switch (((HttpWebResponse)wex.Response).StatusCode)
                    {
                        case HttpStatusCode.Forbidden: HC.DisabledReason = "Current user does not have access to requested resource."; break;
                        case HttpStatusCode.NotFound: HC.DisabledReason = "Record not found."; break;
                        default: HC.DisabledReason = "An unknown response code was received: \"" + ((HttpWebResponse)wex.Response).StatusCode + "\""; break;
                    }
                    HC.Save();

                    Logging.instance.LogError("Unable to update host \"" + HC.Hostname + "\" (" + HC.Provider.ToString() + "): " + HC.DisabledReason);
                }
                catch (Exception ex)
                {
                    HC.Disabled = true;
                    HC.DisabledReason = "Unhandled exception (" + ex.Message + ")";
                    HC.Save();

                    Logging.instance.LogException("Unable to update host \"" + HC.Hostname + "\"", ex);
                }
            }
        }
开发者ID:rickparrish,项目名称:PDDNS,代码行数:51,代码来源:PointProvider.cs

示例10: TryGetHostName

 private static string TryGetHostName(IPAddress address)
 {
     string hostName = null;
     try
     {
         var hostEntry = Dns.GetHostEntry(address);
         hostName = hostEntry != null ? hostEntry.HostName : address.ToString();
     }
     catch
     {
         //Whatever happens, just return address.ToString();
         hostName = address.ToString();
     }
     return hostName;
 }
开发者ID:xyting,项目名称:Hangfire.Redis.StackExchange,代码行数:15,代码来源:RedisStorage.cs

示例11: addPotential

 /// <summary>
 /// Adds a potential IP address 
 /// </summary>
 /// <param name="addr"></param>
 public void addPotential(IPAddress addr)
 {
     if (potentialIPBox.InvokeRequired)
     {
         potentialIPBox.Invoke((MethodInvoker)delegate
         {
             addPotential(addr);
         });
     }
     else
     {
         if (!potentialIPBox.Items.Contains(addr.ToString()))
             this.potentialIPBox.Items.Add(addr.ToString());
     }
 }
开发者ID:hatRiot,项目名称:fireBwall,代码行数:19,代码来源:ScanDetectorUI.cs

示例12: GetNetworkAddressAsString

        public static string GetNetworkAddressAsString(IPAddress address, IPAddress mask)
        {
            string netIP = ""; // Network address as string
            int networkLength = 0;

            if (null != mask)
            {
                for (int i = 0; i < 4; i++)
                {
                    byte ba = address.GetAddressBytes()[i];
                    byte bm = mask.GetAddressBytes()[i];

                    netIP += ba & bm;
                    if (i < 3) netIP += ".";
                    networkLength += 8 - (int)System.Math.Truncate(System.Math.Log(256 - bm, 2));
                }
                netIP += "/" + networkLength;
            }
            else
            {
                netIP = address.ToString() + "/32";
            }

            return netIP;
        }
开发者ID:satur9,项目名称:autoproxyswitcher,代码行数:25,代码来源:NetworkManager.cs

示例13: Server

        public Server(IPAddress ip, int port)
        {
            console = new consoleUI();

            int maxPlayers = 3;

            player = new Client[maxPlayers];
            reservedIDs = new Boolean[maxPlayers];

            for (int i = 0; i < reservedIDs.Length; i++)
            {
                reservedIDs[i] = false;
            }

            try
            {
                tcpListener = new TcpListener(IPAddress.Any, port);
                tcpListener.Start();
            }
            catch (Exception exp)
            {
                console.consoleW("Beim Versuch der Auflösung der Addresse: " + ip.ToString() + " enstand folgender Fehler:\r\n" + exp.Message, "error");
                while (true) ;
            }
        }
开发者ID:freddeyyy,项目名称:mmotest,代码行数:25,代码来源:Server.cs

示例14: VerificationIPAddress

        public static bool VerificationIPAddress(IPAddress ip)
        {
            if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                return VerificationIPAddressV4(ip.ToString());
            }
            else if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
            {
                if (ip.IsIPv6LinkLocal == true || ip.IsIPv6Multicast == true || ip.IsIPv6SiteLocal == true)
                    return false;
                else
                    return VerificationIPAddressV6(ip.ToString());
            }

            return false;
        }
开发者ID:asapo,项目名称:Profes,代码行数:16,代码来源:VerificationIPAddress.cs

示例15: Replace

 public static Uri Replace(Uri url, IPAddress ip)
 {
     var newUriBuilder = new UriBuilder(url);
     newUriBuilder.Host = ip.ToString();
     var newUri = newUriBuilder.Uri;
     return newUri;
 }
开发者ID:Xarlot,项目名称:DXVcs2Git,代码行数:7,代码来源:WebHookHelper.cs


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