コード例 #1
0
ファイル: NAEHandler.cs プロジェクト: kite29/IPBuddy
        public static void PacketHandler(Packet packet)
        {
            Console.WriteLine(packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " Length: " + packet.Length);

            IpV4Datagram ip      = packet.Ethernet.IpV4;
            UdpDatagram  udp     = ip.Udp;
            Datagram     payload = udp.Payload;

            byte[] data = payload.ToArray();
            NAE    nae  = NAEHandler.parseNAEFromPacket(data);
            String msg  = nae.Name + " reported online.";

            NAEHandler.listenFrm.Invoke(NAEHandler.listenFrm.AddNAEDelegate, new object[] { nae });

            if (NAEHandler.mainFrm.notifyIcon.Visible == true)
            {
                NAEHandler.mainFrm.notifyIcon.BalloonTipText = msg;
                NAEHandler.mainFrm.notifyIcon.ShowBalloonTip(500);
            }
            else
            {
                NAEHandler.mainFrm.notifyIcon.Visible        = true;
                NAEHandler.mainFrm.notifyIcon.BalloonTipText = msg;
                NAEHandler.mainFrm.notifyIcon.ShowBalloonTip(500);
                System.Threading.Thread.Sleep(3000);
                NAEHandler.mainFrm.notifyIcon.Visible = false;
            }
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: kite29/IPBuddy
        public frmMain()
        {
            Logger.WriteMessage("Form initializing.");
            InitializeComponent();

            /** Setup grid view **/
            this.dataNAE.Columns.Add("name", "Property");
            this.dataNAE.Columns.Add("value", "Value");
            this.dataNAE.Columns[0].ReadOnly = true;
            this.dataNAE.Columns[1].Width    = (this.dataNAE.Width - this.dataNAE.Columns[0].Width) - 3;

            /** Used for assigning the correct menu to new site and NAE nodes in external classes **/
            frmMain.StaticContextSite = this.contextSite;
            frmMain.StaticContextNAE  = this.contextNAE;

            /** Load NICs into combo box **/
            NIC.LoadNICs(this.comboAdapterList);

            /** Check for existing configuration and load if applicable **/
            if (System.IO.File.Exists("default.xml"))
            {
                try
                {
                    FormHandler.XMLToTree(XDocument.Load("default.xml"), this.treeSites);
                    this.treeSites.ExpandAll();
                }
                catch (Exception e)
                {
                    Logger.WriteMessage("Error in loading default save file.");
                    Logger.WriteException(e);
                    Logger.PromptLogReview("An error occurred trying to load your previously saved configuration.");
                }
            }

            /** Start listening for packets **/
            try
            {
                IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
                if (allDevices.Count > 0)
                {
                    foreach (LivePacketDevice device in allDevices)
                    {
                        NAEListener listener = new NAEListener(device);
                        Task.Run((Action)listener.listen);
                    }
                }
                else
                {
                    MessageBox.Show("No network adapters were detected for listening and the NAE Listener will not function properly. Please ensure you have WinPCap installed.");
                }
            }
            catch (Exception e)
            {
                Logger.WriteMessage("Error in starting packet listeners");
                Logger.WriteException(e);
                Logger.PromptLogReview("An error occurred in starting the listener devices.");
                MessageBox.Show("Please note that since the listener devices failed to start, the NAE Listener tool will not function.");
            }

            /** Setup the NAE Handler **/
            NAEHandler.mainFrm = this;
            NAEHandler.Initialize();

            Logger.WriteMessage("Form initialized.");
        }
コード例 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     NAEHandler.Broadcast();
 }