コード例 #1
0
        /// <summary>
        /// Finds and stores the servers public ip-address.
        /// </summary>
        /// <returns>IPAddress</returns>
        private IPAddress GetPublicIP()
        {
            IPAddress ip = IPAddress.Parse("127.0.0.1");

            using (WebClient webClient = new WebClient())
            {
                try
                {
                    string text = webClient.DownloadString("http://checki.dyndns.org");

                    text = text.Substring(text.LastIndexOfAny(": ".ToCharArray()) + 1);

                    string ipAddr = text.Substring(0, text.IndexOf('<'));

                    ip = IPAddress.Parse(ipAddr);
                }
                catch (WebException)
                {
                    if (MessageBox.Show("Kan inte hitta din publika IP-adress. Tryck Ok för att skriva in den manuellt.") == DialogResult.OK)
                    {
                        string input = InputDialog.OpenDialog("Fyll i ditt ip");
                        if (input != "" && CheckDataInput.IpAddressCheckFormat(input))
                        {
                            ip = IPAddress.Parse(input);
                        }
                    }
                }
            }

            return(ip);
        }
コード例 #2
0
        private void buttonConnectToIP_Click(object sender, EventArgs e)
        {
            string input = InputDialog.OpenDialog("Skriv in det ip du vill ansluta till");

            if (input != "" && CheckDataInput.IpAddressCheckFormat(input))
            {
                ConnectToIp(input);
            }

            else
            {
                MessageBox.Show("Inte en korrekt ip-adress!");
            }
        }