コード例 #1
0
        /// <summary>
        /// 获取本地IP及公网IP
        /// </summary>
        private void GetIP(object sender, EventArgs e)
        {
            LocalIP = Dns.GetHostAddresses(Dns.GetHostName()).Where(ip => ip.AddressFamily.ToString().Equals("InterNetwork")).FirstOrDefault();

            using (var s = WebRequest.Create("https://www.ipip5.com/").GetResponse().GetResponseStream())
            {
                using (var stream = new StreamReader(s, Encoding.UTF8))
                {
                    var str   = stream.ReadToEnd();
                    int first = str.IndexOf("<span class=\"c-ip\">") + 19;
                    int last  = str.IndexOf("</span>", first);
                    var pip   = str.Substring(first, last - first);
                    PublicIP = IPAddress.Parse(str.Substring(first, last - first));
                }
            }

            Txt_LocalIP.Text   = LocalIP.ToString();
            Txt_LocalPort.Text = "1232";
        }
コード例 #2
0
        private void ProcessCommandDeployApp(List <ClusterNode> ClusterNodes)
        {
            HashSet <string> NodesSent = new HashSet <string>();

            // Add local IPs so we don't copy on current host
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (var LocalIP in localIPs)
            {
                NodesSent.Add(LocalIP.ToString());
            }

            foreach (ClusterNode Node in ClusterNodes)
            {
                if (!NodesSent.Contains(Node.address))
                {
                    NodesSent.Add(Node.address);
                    DeployDir(Path.GetDirectoryName(SelectedApplication), Path.GetDirectoryName(SelectedApplication), Node);
                }
            }
        }
コード例 #3
0
        public void BeginNatDiscovery()
        {
            // determine which local address used for NAT discovery
            string localAddress = string.Empty;

            if (LocalIP == null)
            {
                var localIP = SoftPhoneFactory.GetLocalIP();
                if (localIP != null)
                {
                    localAddress = localIP.ToString();
                }
            }
            else
            {
                localAddress = LocalIP.ToString();
            }


            // begin NAT discovery
            softPhone.BeginNatDiscovery(localAddress, "stun.ozekiphone.com", Callback);
        }
コード例 #4
0
ファイル: Default.aspx.cs プロジェクト: mossane/LanContain
    bool IsLanIP(string LanIP)
    {
        bool BoolLan = false;

        try
        {
            IPAddress[] LocalIPs = Dns.GetHostEntry(Dns.GetHostName()).AddressList;

            foreach (IPAddress LocalIP in LocalIPs)
            {
                if (LocalIP.ToString().IndexOf(':') == -1)
                {
                    if (LanIP.Substring(0, LanIP.LastIndexOf('.')) == LocalIP.ToString().Substring(0, LocalIP.ToString().LastIndexOf('.')))
                    {
                        BoolLan = true;
                    }
                }
            }
        }
        catch (Exception ex) { this.Label2.Text = "是否局域网IP地址:" + ex.Message.ToString(); }

        return(BoolLan);
    }
コード例 #5
0
        private void ProcessCommandStartListeners(List <ClusterNode> ClusterNodes)
        {
            if (String.IsNullOrEmpty(SelectedApplication))
            {
                AppLogger.Add("ERROR! No selected application");
                return;
            }

            // It supposed that listener application is exist alongside the application. Let's check it out.
            string ListenerFilePath = Path.Combine(Path.GetDirectoryName(SelectedApplication), ListenerAppName);

            if (!File.Exists(ListenerFilePath))
            {
                AppLogger.Add(string.Format("Listener application {0} not found", ListenerFilePath));
                return;
            }

            // Ok, we have listener application available on the local PC. It's possible that some remote machine has no listener available.
            // To make sure it's available everywhere we deploy listener application.
            HashSet <string> NodesSent = new HashSet <string>();

            // Add local IPs so we don't copy on current host
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
            foreach (var LocalIP in localIPs)
            {
                NodesSent.Add(LocalIP.ToString());
            }

            // Upload listener
            foreach (ClusterNode Node in ClusterNodes)
            {
                if (!NodesSent.Contains(Node.address))
                {
                    // Deploy the listener application if it doesn't exist on remote machine
                    string RemoteListenerPath = GenerateRemotePath(Node, ListenerFilePath);
                    if (!File.Exists(RemoteListenerPath))
                    {
                        DeployFile(ListenerFilePath, Path.GetDirectoryName(ListenerFilePath), Node);
                    }
                }
            }

            // Now we're ready to start listeners remotely
            KeyValuePair <string, string>[] SchTaskCmds = new KeyValuePair <string, string>[]
            {
                new KeyValuePair <string, string>(
                    String.Format("SCHTASKS /Create /TN StartClusterListener /TR \\\"{0}\\\" /SC ONEVENT /EC Application /MO *[System/EventID=777] /f", ListenerFilePath),
                    "Task registration"),

                new KeyValuePair <string, string>(
                    "SCHTASKS /RUN /TN StartClusterListener",
                    "Task activation")
            };

            NodesSent.Clear();
            foreach (ClusterNode Node in ClusterNodes)
            {
                if (!NodesSent.Contains(Node.address))
                {
                    foreach (var Cmd in SchTaskCmds)
                    {
                        NodesSent.Add(Node.address);

                        string appPath = "wmic";
                        string argList = string.Format("/node:\"{0}\" process call create \"{1}\"", Node.address, Cmd.Key);

                        SpawnRemoteProcess(Cmd.Value, Node.address, appPath, argList);
                    }
                }
            }

            // Finally, let's check if all listeners have been started successfully
            NodesSent.Clear();
            foreach (ClusterNode Node in ClusterNodes)
            {
                if (!NodesSent.Contains(Node.address))
                {
                    NodesSent.Add(Node.address);

                    int ResponseCode = SendDaemonCommand(Node.address, CommandStatus);
                    if (ResponseCode != 0)
                    {
                        AppLogger.Add("Couldn't start the listener on " + Node.address);
                    }
                }
            }
        }
コード例 #6
0
ファイル: UPnP.cs プロジェクト: saa1963/TinyOPDS
 public void ForwardPort(int port, ProtocolType protocol, string description)
 {
     if (UPnPReady)
     {
         SOAPRequest(_serviceUrl,
                     "<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" +
                     "<NewRemoteHost></NewRemoteHost><NewExternalPort>" + port.ToString() + "</NewExternalPort><NewProtocol>" + protocol.ToString().ToUpper() + "</NewProtocol>" +
                     "<NewInternalPort>" + port.ToString() + "</NewInternalPort><NewInternalClient>" + LocalIP.ToString() +
                     "</NewInternalClient><NewEnabled>1</NewEnabled><NewPortMappingDescription>" + description +
                     "</NewPortMappingDescription><NewLeaseDuration>0</NewLeaseDuration></u:AddPortMapping>", "AddPortMapping");
     }
 }