Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string username = this.textBox1.Text.ToUpper().Trim();
            string password = this.textBox2.Text.Trim();

            if (username == "" || password == "")
            {
                MessageBox.Show("用戶名或密碼不能為空", "提示", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            if (!userBLL.checkLogin(username, password))
            {
                MessageBox.Show("用戶名或密碼錯誤", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox2.Text = "";
                this.textBox2.Focus();
                return;
            }
            if (this.comboBox1.SelectedValue == null || this.comboBox1.SelectedValue.ToString().Trim() == "")
            {
                MessageBox.Show("角色不能為空,請重新確認用戶名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox1.Focus();
                return;
            }
            user = textBox1.Text.Trim();
            string ipAddress = LocalIP.GetLocalIP();

            userBLL.saveLoginInfo(username, ipAddress);
            Auxiliary.loginName = username;
            Auxiliary.RoleNo    = this.comboBox1.SelectedValue.ToString().Trim();
            MainMenuMDI mainMenuMDI = new MainMenuMDI();

            mainMenuMDI.Show();
            this.Hide();
        }
 public override int GetHashCode()
 {
     return
         ((HMDeviceID != null ? HMDeviceID.GetHashCode() : 0) +
          (MQTTRootTopicLevel != null ? MQTTRootTopicLevel.GetHashCode() : 0) +
          (Version != null ? Version.GetHashCode() : 0) +
          (Status.GetHashCode()) +
          (Name != null ? Name.GetHashCode() : 0) +
          (LocalIP != null ? LocalIP.GetHashCode() : 0) +
          (MAC != null ? MAC.GetHashCode() : 0) +
          (UpTime != null ? UpTime.GetHashCode() : 0) +
          (Signal != null ? Signal.GetHashCode() : 0)); //finish
 }
Beispiel #3
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";
        }
Beispiel #4
0
        /// <summary>
        /// Подключает клиента к удаленному BDTP-узлу, используя указанный IP-адрес.
        /// </summary>
        /// <param name="remoteIP">Объект IPAddress узла, к которому выполняется подключение.</param>
        /// <returns>true Если удалось установить соединение; в противном случае — false.</returns>
        public virtual bool Connect(IPAddress remoteIP)
        {
            if (Connected)
            {
                return(false);
            }

            try
            {
                tcpController = new TcpClient();
                tcpController.Connect(remoteIP, TcpPort);
            }
            catch { return(false); }

            SendReceipt(LocalIP.GetAddressBytes());

            RemoteIP = remoteIP;
            return(true);
        }
        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);
                }
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
    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);
    }
Beispiel #8
0
        public override bool Equals(object obj)
        {
            Adapter a;

            try
            {
                a = (Adapter)obj;
            }
            catch (InvalidCastException)
            {
                return(false);
            }

            if (MyMACAddress == null)
            {
                if (a.MyMACAddress != null)
                {
                    return(false);
                }
            }
            else if (!MyMACAddress.Equals(a.MyMACAddress))
            {
                return(false);
            }

            if (LocalIP == null)
            {
                if (a.LocalIP != null)
                {
                    return(false);
                }
            }
            else if (!LocalIP.Equals(a.LocalIP))
            {
                return(false);
            }

            if (SubnetMask == null)
            {
                if (a.SubnetMask != null)
                {
                    return(false);
                }
            }
            else if (!SubnetMask.Equals(a.SubnetMask))
            {
                return(false);
            }

            if (DefaultGateway == null)
            {
                if (a.DefaultGateway != null)
                {
                    return(false);
                }
            }
            else if (!DefaultGateway.Equals(a.DefaultGateway))
            {
                return(false);
            }

            if (DNS == null)
            {
                if (a.DNS != null)
                {
                    return(false);
                }
            }
            else if (!DNS.Equals(a.DNS))
            {
                return(false);
            }


            if ((Name == a.Name) && (OtherEndID == a.OtherEndID) && (Connected == a.Connected) && (Associated == a.Associated))
            {
                return(true);
            }
            return(false);
        }
Beispiel #9
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);
                    }
                }
            }
        }
Beispiel #10
0
 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");
     }
 }
Beispiel #11
0
        public void SetRule()
        {
            txtName.Text        = NameRule;
            txtDescription.Text = Description;
            if (State == "Yes")
            {
                ckState.Checked = true;
            }
            else
            {
                ckState.Checked = false;
            }
            if (Action == "Allow")
            {
                rbAllow.Checked = true;
            }
            else
            {
                rbBlock.Checked = true;
            }
            if (Program == "Any")
            {
                rbAllProgram.Checked = true;
                txtProgram.Enabled   = false;
                btnBrowes.Enabled    = false;
            }
            else
            {
                rbThisProgram.Checked = true;
                txtProgram.Text       = Program;
                btnBrowes.Enabled     = true;
            }
            switch (Profile)
            {
            case "Domain":
            {
                cbDomain.Checked  = true;
                cbPrivate.Checked = false;
                cbPublic.Checked  = false;
                break;
            }

            case "Domain, Private":
            {
                cbDomain.Checked  = true;
                cbPrivate.Checked = true;
                cbPublic.Checked  = false;
                break;
            }

            case "Domain, Private, Public":
            {
                cbDomain.Checked  = true;
                cbPrivate.Checked = true;
                cbPublic.Checked  = true;
                break;
            }

            case "Domain, Public":
            {
                cbDomain.Checked  = true;
                cbPrivate.Checked = false;
                cbPublic.Checked  = true;
                break;
            }

            case "Private":
            {
                cbDomain.Checked  = false;
                cbPrivate.Checked = true;
                cbPublic.Checked  = false;
                break;
            }

            case "Private, Public":
            {
                cbDomain.Checked  = false;
                cbPrivate.Checked = true;
                cbPublic.Checked  = true;
                break;
            }

            case "Public":
            {
                cbDomain.Checked  = false;
                cbPrivate.Checked = false;
                cbPublic.Checked  = true;
                break;
            }
            }
            cbProtocol.Text = Protocol;
            if (LocalPort == "Any")
            {
                cbLocalport.SelectedIndex = 0;
                txtLocalport.Enabled      = false;
            }
            else
            {
                cbLocalport.SelectedIndex = 1;
                txtLocalport.Enabled      = true;
                txtLocalport.Text         = LocalPort;
            }
            if (RemotePort == "Any")
            {
                cbRemoteport.SelectedIndex = 0;
                txtRemoteport.Enabled      = false;
            }
            else
            {
                cbRemoteport.SelectedIndex = 1;
                txtRemoteport.Enabled      = true;
                txtRemoteport.Text         = RemotePort;
            }
            if (LocalIP == "Any")
            {
                rbAllLocal.Checked   = true;
                btnAddLocal.Enabled  = false;
                btnEditLocal.Enabled = false;
                btnDelLocal.Enabled  = false;
            }
            else
            {
                rbIPLocal.Checked    = true;
                btnAddLocal.Enabled  = true;
                btnEditLocal.Enabled = false;
                btnDelLocal.Enabled  = false;
                string[] s = LocalIP.Split(',');
                for (int i = 0; i < s.Length; i++)
                {
                    listView1.Items.Add(s[i]);
                }
            }
            if (RemoteIP == "Any")
            {
                rbAllRemote.Checked   = true;
                btnAddRemote.Enabled  = false;
                btnEditRemote.Enabled = false;
                btnDelRemote.Enabled  = false;
            }
            else
            {
                rbIPLocal.Checked     = true;
                btnAddRemote.Enabled  = true;
                btnEditRemote.Enabled = false;
                btnDelRemote.Enabled  = false;
                string[] s = RemoteIP.Split(',');
                for (int i = 0; i < s.Length; i++)
                {
                    listView2.Items.Add(s[i]);
                }
            }
            var firewallRule = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));

            foreach (INetFwRule rule in firewallRule.Rules)
            {
                if (NameRule == rule.Name)
                {
                    string s = rule.Grouping;
                    if (s != null)
                    {
                        txtName.ReadOnly        = true;
                        txtDescription.ReadOnly = true;
                        rbAllProgram.Enabled    = false;
                        rbThisProgram.Enabled   = false;
                        txtProgram.ReadOnly     = true;
                        btnBrowes.Enabled       = false;
                        cbProtocol.Enabled      = false;
                        cbLocalport.Enabled     = false;
                        cbRemoteport.Enabled    = false;
                        txtLocalport.Enabled    = false;
                        txtRemoteport.Enabled   = false;
                    }
                    else
                    {
                        txtName.ReadOnly        = false;
                        txtDescription.ReadOnly = false;
                        rbAllProgram.Enabled    = true;
                        rbThisProgram.Enabled   = true;
                        txtProgram.ReadOnly     = false;
                        if (rbThisProgram.Checked == true)
                        {
                            btnBrowes.Enabled = true;
                        }
                    }
                }
            }
        }