public ToolUI()
        {
            InitializeComponent();

            //Change the icon and add the version to the title
            Icon = Properties.Resources.iw4sp_1;
            Text += " " + Assembly.GetExecutingAssembly().GetName().Version;

            //Device listing
            try
            {
                //Get devices
                captureDevices = SharpPcap.CaptureDeviceList.Instance;

                //Add devices to the list
                foreach (ICaptureDevice captureDevice in captureDevices)
                {
                    Int32 index= deviceList.Items.Add(captureDevice);

                    if (captureDevice.Description == Settings.Default.CaptureDevice)
                        deviceList.SelectedIndex = index;

                }

                //Select the first device if nothing is selected
                if (deviceList.SelectedIndex==-1 && deviceList.Items.Count > 0)
                    deviceList.SelectedIndex = 0;
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 2
0
        private ICaptureDevice _device = null; //捕获网卡

        #endregion Fields

        #region Constructors

        //        private bool _threadabort;          //是否应该停止线程
        public Form1()
        {
            InitializeComponent();
            button2.Enabled = false;
            PacketQueue.Add(AllPacketQ);
            PacketQueue.Add(ArpPacketQ);
            PacketQueue.Add(IpPacketQ);
            PacketQueue.Add(TcpPacketQ);
            PacketQueue.Add(UdpPacketQ);
            PacketQueue.Add(HttpPacketQ);
            devices = CaptureDeviceList.Instance;
            //显示网卡信息
            foreach (var dev in devices)
            {
                this.comboBox1.Items.Add(dev.Description);
            }
        }
Ejemplo n.º 3
0
        public void sniff()
        {
            r_id = 1;
            // Print SharpPcap version
            string ver = SharpPcap.Version.VersionString;
            Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);

            // Retrieve the device list
            devices = CaptureDeviceList.Instance;

            // If no devices were found print an error
            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine("\nThe following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------\n");

            // Print out the available network devices
            foreach (ICaptureDevice dev in devices)
                Console.WriteLine("{0}\n", dev.ToString());

            Console.Write("Hit 'Enter' to exit...");
            // Console.ReadLine();
            // Extract a device from the list
            device = devices[0];

            // Register our handler function to the
            // 'packet arrival' event
            device.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);

            // Open the device for capturing
            int readTimeoutMilliseconds = 1000;
            device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

            Console.WriteLine("-- Listening on {0}, hit 'Enter' to stop...", device.Description);

            // Start the capturing process
            device.StartCapture();

            // Wait for 'Enter' from the user.
            //while (true) { };
        }
Ejemplo n.º 4
0
 public PacketAnalyzer()
 {
     this.form = Program.form;
     string ver = SharpPcap.Version.VersionString;
     logText("SharpPcap " + ver);
     logText("");
     devices = CaptureDeviceList.Instance;
     if (devices.Count < 1)
     {
         logText("No device found on this machine");
         return;
     }
     devNames = new String[devices.Count];
     for (int i = 0; i < devNames.Length; i++)
     {
         devNames[i] = devices[i].Description;
     }
     form.SetDevicesNames(devNames);
 }
Ejemplo n.º 5
0
        private void Initialize()
        {
            PacketCount = 0;
            start.Enabled = true;
            pause.Enabled = false;
            reset.Enabled = false;
            save.Enabled = false;
            export.Enabled = false;

            FilterExp.Text = (FilterRule == "") ? "all pass" : FilterRule;

            Control.CheckForIllegalCrossThreadCalls = false;// Allowing crossing thread calling form.
            devices = CaptureDeviceList.Instance;// Instatiation of alternative capture devices.
            foreach (ICaptureDevice dev in devices)
                DeviceList.Items.Add(dev.Description.ToString());// Gets devices' names.
            RawCaptureList = new List<RawCapture>();
            
            sorter = new columnSorter();
            this.TotalPacket.ListViewItemSorter = sorter;// Customized sorter for increasing/decreasing sorting.
            }
Ejemplo n.º 6
0
        public Mainfrm()
        {
            InitializeComponent();

            CaptureDeviceList capture_device_list = new CaptureDeviceList();

            if (capture_device_list.count < 1)
            {
                MessageBox.Show("The capture system is not found.");
                return;
            }
            CaptureDevice capture_device = capture_device_list[0];

            this.setup(capture_device);
            if (this._d3d == null)
            {
                this._d3d = prepareD3dDevice(this, this._dpp);
            }

            this.Shown += Mainfrm_Shown;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 加载网卡,通过BackgroundWorker获取进度显示在启动界面的进度条上
 /// </summary>
 /// <param name="bw"></param>
 public static void LoadDevices(BackgroundWorker bw)
 {
     bw.ReportProgress(25);
     devices = CaptureDeviceList.Instance;
     bw.ReportProgress(50);
     if (devices.Count >= 1)
     {
         int cnt    = 25 / devices.Count;
         int cntrep = 75;
         foreach (var dev in devices)
         {
             cntrep += cnt;
             bw.ReportProgress(cntrep);
             string name = dev.ToString();
             name = name.Substring(name.IndexOf("FriendlyName"));
             name = name.Substring(13, name.IndexOf('\n') - 13);
             comboBox.Items.Add(name);
             Thread.Sleep(100);
         }
     }
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            string ver = SharpPcap.Version.VersionString;

            Console.WriteLine("SharpPcap {0}", ver);


            CaptureDeviceList devices = CaptureDeviceList.Instance;

            if (devices.Count < 1)
            {
                Console.WriteLine("No devices found.");
            }

            Console.WriteLine("Devices found:");
            devices.ToList().ForEach(Console.WriteLine);


            ICaptureDevice localAreaNetworkNIC = devices[1];

            localAreaNetworkNIC.OnPacketArrival += new PacketArrivalEventHandler(localAreaNetworkNIC_OnPacketArrival);

            // open device
            int readTimeoutMill = 1000;

            localAreaNetworkNIC.Open(DeviceMode.Promiscuous, readTimeoutMill);

            localAreaNetworkNIC.Filter = "ip and tcp";

            Console.WriteLine("Filtering: {0}", localAreaNetworkNIC.Filter);
            Console.WriteLine("Listening on {0}", localAreaNetworkNIC.Description);

            localAreaNetworkNIC.StartCapture();

            Console.ReadLine();

            localAreaNetworkNIC.StopCapture();

            localAreaNetworkNIC.Close();
        }
Ejemplo n.º 9
0
        private void btnCap_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CaptureDeviceList cdevices = CaptureDeviceList.Instance;
                if (cdevices.Count >= 1)
                {
                    gbxDeviceList.Header = cdevices.Count + " Devices";
                    foreach (ICaptureDevice dev in cdevices)
                    {
                        if (dev is AirPcapDevice)
                        {
                            lbxAirPcapDeviceList.Items.Add(dev as AirPcapDevice);
                        }
                        else if (dev is WinPcapDevice)
                        {
                            lbxWinPcapDeviceList.Items.Add(dev as WinPcapDevice);
                        }
                        else if (dev is LibPcapLiveDevice)
                        {
                            lbxLibPcapLiveDeviceList.Items.Add(dev as LibPcapLiveDevice);
                        }
                    }
                }
                else
                {
                    gbxDeviceList.Header = "No Devices";
                }

                /* // check device isn't null
                 * if (cdevices.Count < 1 || cdevices == null)
                 *   throw new NullReferenceException();*/

                gbxDeviceList.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
            }
        }
        public static ICaptureDevice AskForPacketDevice()
        {
            // Retrieve the device list from the local machine
            CaptureDeviceList devices = CaptureDeviceList.Instance;

            if (devices.Count == 0)
            {
                throw new Exception("No interfaces found! Make sure WinPcap is installed.");
            }

            // Print the list
            for (int i = 0; i != devices.Count; ++i)
            {
                ICaptureDevice device = devices[i];
                Console.Write((i + 1) + ". ");
                if (device.Description != null)
                {
                    Console.WriteLine(" (" + device.Description + ")");
                }
                else
                {
                    Console.WriteLine(" (No description available)");
                }
            }

            int deviceIndex;

            do
            {
                Console.WriteLine("Enter the interface number (1-" + devices.Count + "):");
                string deviceIndexString = Console.ReadLine();
                if (!int.TryParse(deviceIndexString, out deviceIndex) ||
                    deviceIndex < 1 || deviceIndex > devices.Count)
                {
                    deviceIndex = 0;
                }
            } while (deviceIndex == 0);

            return(devices[deviceIndex - 1]);
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            string ver = SharpPcap.Version.VersionString;

            Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);

            CaptureDeviceList devices = CaptureDeviceList.Instance;

            ICaptureDevice device = devices[0];

            // Register our handler function to the
            // 'packet arrival' event
            device.OnPacketArrival +=
                new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);

            // Open the device for capturing
            int readTimeoutMilliseconds = 1000;

            device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device.Filter = "ip and tcp";

            Console.WriteLine("-- Listening on {0}, hit 'Enter' to stop...",
                              device.Description);

            // Start the capturing process
            device.StartCapture();

            // Wait for 'Enter' from the user.
            Console.ReadLine();

            // Stop the capturing process
            device.StopCapture();

            // Close the pcap device
            device.Close();

            Console.Write("Hit 'Enter' to exit...");
            Console.ReadLine();
        }
Ejemplo n.º 12
0
        private void SetupForm_Load(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;

                var devices = CaptureDeviceList.Instance;

                Devices = devices;

                cmbAdapter.Invoke(() =>
                {
                    cmbAdapter.Enabled = true;

                    foreach (var dev in devices)
                    {
                        /* Description */
                        //Console.WriteLine("{0}) {1} {2}", i, dev.Name, dev.Description);

                        cmbAdapter.Items.Add($"{((LibPcapLiveDevice)dev).Interface.FriendlyName}");
                    }

                    if (devices.Count > 0)
                    {
                        cmbAdapter.SelectedIndex = 0;
                    }
                });

                StatusStrip.Invoke(() =>
                {
                    StatusLabel.Text = "Ready";
                });

                BtnSelect.Invoke(() =>
                {
                    BtnSelect.Enabled = true;
                });
            }).Start();
        }
Ejemplo n.º 13
0
 public void SetDevices(CaptureDeviceList devices)
 {
     _devices = devices;
     foreach (ICaptureDevice dev in _devices)
     {
         if (dev is AirPcapDevice)
         {
             AirPcapDevice cpd = dev as AirPcapDevice;
             devicesList.Items.Add(cpd.Interface.FriendlyName + " - " + dev.Description.ToString());
         }
         else if (dev is WinPcapDevice)
         {
             WinPcapDevice cpd = dev as WinPcapDevice;
             devicesList.Items.Add(cpd.Interface.FriendlyName + " - " + dev.Description.ToString());
         }
         else if (dev is LibPcapLiveDevice)
         {
             LibPcapLiveDevice cpd = dev as LibPcapLiveDevice;
             devicesList.Items.Add(cpd.Interface.FriendlyName + " - " + dev.Description.ToString());
         }
     }
 }
Ejemplo n.º 14
0
        public static void getDevices()
        {
            string ver = SharpPcap.Version.VersionString;

            Console.WriteLine("SharpPcap {0}, Example1.IfList.cs", ver);

            CaptureDeviceList devices = CaptureDeviceList.Instance;

            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine("\nThe following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------\n");

            foreach (ICaptureDevice dev in devices)
            {
                Console.WriteLine("{0}\n", dev.ToString());
            }
        }
Ejemplo n.º 15
0
        public Form1()
        {
            InitializeComponent();

            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), 640, 480);


            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE), 16, 16);

            NyARDoubleMatrix44 result_mat = new NyARDoubleMatrix44();
            CaptureDeviceList  cl         = new CaptureDeviceList();
            CaptureDevice      cap        = cl[0];

            cap.SetCaptureListener(this);
            cap.PrepareCapture(640, 480, 30);
            this.m_cap = cap;

            this.m_raster = new DsRgbRaster(cap.video_width, cap.video_height);

            this.m_ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0);
            this.m_ar.setContinueMode(false);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 从所有网卡上开始抓包
        /// </summary>
        public void startCapture()
        {
            Debug.WriteLine("[+]一个游戏( " + port + " )准备开始抓包...");
            this.bufferList = new List <RawCapture>();
            this.clear();         // 清理原有的数据
            this.isStartAnalyzer = true;
            this.startAnalyzer(); // 启动分析线程
            naList = new List <ICaptureDevice>();

            //foreach (ICaptureDevice device in CaptureDeviceManager.getInstance()) {
            var devices = CaptureDeviceManager.getInstance();

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i].Description.Contains("VMware") || devices[i].Description.Contains("TAP-Windows Adapter"))
                {
                    Debug.WriteLine("[-]端口( " + port + " )在" + devices[i].Description + " 已忽略...");
                    continue; //跳过虚拟网卡和SS-TAP
                }
                // 这里必须使用CaptureDeviceList.New()[i]获取新实例, 虽然很慢, 但是没有解决办法
                // 如果使用devices[i] 那表示使用的还是同一块网卡, 绑定多个过滤器, 并不是多网卡实例 会导致多个Game收到同样的内容
                ICaptureDevice device = CaptureDeviceList.New()[i];
                //ICaptureDevice device = devices[i];

                try {
                    device.OnPacketArrival += new PacketArrivalEventHandler(this.device_OnPacketArrival);
                    device.Open(Settings.devMode, Settings.readTimeOut);
                    device.Filter = "port " + this.port;
                    device.StartCapture();
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
                naList.Add(device);
                Debug.WriteLine("[+]端口( " + port + " )在" + device.Description + " 初始化完毕...");
            }
            this.isStartMonitor = true;
            this.startMonitor();// 启动掉线监测
            Debug.WriteLine("[+]一个游戏( " + port + " )抓包已启动完毕...");
        }
Ejemplo n.º 17
0
        private void scan_transfer_speed(String devicename, String ipadd)
        {
            CaptureDeviceList devices = CaptureDeviceList.New();

            foreach (WinPcapDevice d in devices)
            {
                if (d.Interface.FriendlyName == devicename)
                {
                    _device = d;
                    break;
                }
            }

            if (_device != null)
            {
                _device.OnPcapStatistics += new StatisticsModeEventHandler(update_statistics);
                _device.Open(DeviceMode.Promiscuous, 1000);
                _device.Filter = "(tcp or udp) and host " + ipadd;
                _device.Mode   = CaptureMode.Statistics;
                _device.StartCapture();
            }
        }
Ejemplo n.º 18
0
 void start()
 {
     if (captureDevice != null)
     {
         MessageBox.Show("Sniffer already started");
         return;
     }
     try
     {
         CaptureDeviceList deviceList = CaptureDeviceList.Instance;
         captureDevice = deviceList[4];
         captureDevice.OnPacketArrival += new PacketArrivalEventHandler(Program_OnPacketArrival);
         // открываем в режиме promiscuous, поддерживается также нормальный режим
         captureDevice.Open(DeviceMode.Promiscuous, 1000);
         // начинаем захват пакетов
         captureDevice.Capture();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Ejemplo n.º 19
0
        public MainWindow()
        {
            InitializeComponent();

            CaptureDeviceList cl = new CaptureDeviceList();

            m_cap = cl[0];
            m_cap.SetCaptureListener(this);
            m_cap.PrepareCapture(800, 600, 30);

            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), 800, 600);

            this.m_raster = new NyARRgbRaster_BYTE1D_B8G8R8_24(m_cap.video_width, m_cap.video_height, false);

            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE), 16, 16);

            this.m_ar = new NyARDetectMarker(ap, new NyARCode[] { code }, new double[] { 80.0 }, 1);
            this.m_ar.setContinueMode(false);

            this.Loaded  += MainWindow_Loaded;
            this.Closing += MainWindow_Closing;
        }
Ejemplo n.º 20
0
 public Form3(string type)
 {
     InitializeComponent();
     this.Text = type;
     if (type == "Devices")
     {
         CaptureDeviceList list = CaptureDeviceList.Instance;
         foreach (ICaptureDevice i in list)
         {
             richTextBox1.Text += Convert.ToString(i);
         }
     }
     else if (type == "Instruction")
     {
         string[] lines = File.ReadAllLines(@"Instruction.txt", Encoding.GetEncoding(1251));
         foreach (string inst in lines)
         {
             richTextBox1.Text += inst;
             richTextBox1.Text += "\n";
         }
     }
 }
Ejemplo n.º 21
0
        //ToolTip toolTip1 = new ToolTip();

        public PeerMapStart()
        {
            InitializeComponent();
            lblMessage.Visibility = Visibility.Collapsed;
            try
            {
                devices = CaptureDeviceList.Instance;
            }
            catch
            {
                lblMessage.Text       = "没有发现可用的网络适配器,请检查网卡设置以及是否安装WinPcap";
                lblMessage.Visibility = Visibility.Visible;
                return;
            }
            for (int i = 0; i < devices.Count; i++)
            {
                ICaptureDevice dev      = devices[i];
                RadioButton    radioBtn = new RadioButton();

                radioBtn.Content = dev.Description;
                //radioBtn.AutoSize = true;
                radioBtn.HorizontalContentAlignment = HorizontalAlignment.Left;
                //radioBtn.TextAlign = ContentAlignment.MiddleLeft;
                radioBtn.ToolTip = dev.ToString();
                //toolTip1.SetToolTip(radioBtn, dev.ToString());
                radioBtns.Add(radioBtn);
                canvas.Children.Add(radioBtn);
                Canvas.SetLeft(radioBtn, 30d);
                Canvas.SetTop(radioBtn, 20.0 + 20.0 * i);

//                 radioBtn.Location = new Point(30, 20 + 20 * i);
//                 this.gBoxPeerMap.Controls.Add(radioBtns[i]);
            }
            if (devices.Count == 1)
            {
                radioBtns[0].IsChecked = true;
            }
        }
Ejemplo n.º 22
0
        ICaptureDevice checkIfDeviceExists(string deviceName, CaptureDeviceList devices)
        {
            bool           isThere        = false;
            ICaptureDevice deviceToReturn = devices[0];

            foreach (var dev in devices)
            {
                if (dev.Name == deviceName)
                {
                    isThere        = true;
                    deviceToReturn = dev;
                    break;
                }
            }

            if (!isThere)
            {
                Console.WriteLine("GIVEN DEVICE IS NOT EXISTS!");
                Environment.Exit(10);
            }

            return(deviceToReturn);
        }
Ejemplo n.º 23
0
        public static CaptureDeviceList GetDevice()
        {
            var devices = CaptureDeviceList.New();

            if (devices.Count < 1)
            {
                return(null);
            }
            Regex r = new Regex("FriendlyName:(.+)");
            int   i = 0;

            OutPut("List of Current Adapters.Modify the adapter index to capture.");
            foreach (var d in devices)
            {
                string info         = d.ToString();
                string friendlyName = r.Match(info).Groups[1].Value;
                OutPut("[" + i + "] " + friendlyName);
                //OutPut(d.ToString());
                i++;
            }
            OutPut("------------------------------------------------------------");
            return(devices);
        }
Ejemplo n.º 24
0
 private static bool InitInterfaces()
 {
     try
     {
         _list = CaptureDeviceList.Instance;
     }
     catch (Exception)
     {
         if (!Mad.GUI_USED)
         {
             Console.WriteLine("Error: Please check if you have installed WinPcap");
         }
         else
         {
             System.Windows.Forms.MessageBox.Show("Error: Please check if you have installed WinPcap", "ERROR", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         }
         return(false);
     }
     _dev = _list[(int)networkInterface];
     _dev.Open();
     _listenDev = _list[(int)networkInterface];
     return(true);
 }
Ejemplo n.º 25
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ServiceController service = new ServiceController("RemoteAccess");

            if (service.ServiceName == "RemoteAccess")
            {
                if (service.Status.ToString() != "Running")
                {
                    button2.Text = "Enrutamiento: OFF";
                }
                else
                {
                    button2.Text = "Enrutamiento: ON";
                }
            }

            CaptureDeviceList devices = CaptureDeviceList.Instance;

            foreach (ICaptureDevice objeto in devices)
            {
                comboBox1.Items.Add(objeto.Description);
            }
        }
Ejemplo n.º 26
0
        public void SelectedCaptureDevice(IpInterface selectedIpInterface)
        {
            this.Clear();
            CaptureDeviceList deviceList = CaptureDeviceList.Instance;

            foreach (var device in deviceList.OfType <NpcapDevice>())
            {
                if (device.Name == selectedIpInterface?.HwName)
                {
                    this.Add(device);
                }

                if (device.Interface.Addresses.Count > 0) // just for the debugging purpose - save the local MacAddresses
                {
                    this.AddLocalPhysicalAddress(device.Interface.MacAddress);
                }
            }

            if (!this.Any())                                         //no device found, let's make an assumption and pick first
            {
                this.Add(deviceList.OfType <NpcapDevice>().First()); // if we take all -> huge perf fckup
            }
        }
Ejemplo n.º 27
0
        public CameraPnl2()
        {
            InitializeComponent();

            CaptureDeviceList oCaptureDeviceList = new CaptureDeviceList();

            MyCaptureDevice = oCaptureDeviceList[4];
            MyCaptureDevice.SetCaptureListener(this);
            MyCaptureDevice.PrepareCapture(640, 480, 30.0f);

            INyARMarkerSystemConfig oMarkerSystemConfig = new NyARMarkerSystemConfig(640, 480);

            this.ARMarkerSystem = new NyARD3dMarkerSystem(oMarkerSystemConfig);
            this.ARCameraSensor = new NyARDirectShowCamera(MyCaptureDevice);

            this.MarkerID_Hiro  = this.ARMarkerSystem.addARMarker(AR_CODE_FILE1, 16, 25, 80);
            this.MarkerID_KanJi = this.ARMarkerSystem.addARMarker(AR_CODE_FILE2, 16, 25, 80);
            this.MarkerID_VTT   = this.ARMarkerSystem.addARMarker(AR_CODE_FILE3, 16, 25, 80);
            this.MarkerID_ABB   = this.ARMarkerSystem.addARMarker(AR_CODE_FILE4, 16, 25, 80);
            this.Marker_Hello   = this.ARMarkerSystem.addARMarker(AR_CODE_FILE5, 16, 25, 80);

            this.Loaded += CameraPnl1_Loaded;
        }
Ejemplo n.º 28
0
        public static void caputureDevice()
        {
            CaptureDeviceList devices = CaptureDeviceList.Instance;

            Console.WriteLine("Enter device number");

            try
            {
                int i = int.Parse(Console.ReadLine());

                ICaptureDevice device = devices[i];

                device.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);

                int readTimeoutMilliseconds = 1000;
                device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

                Console.WriteLine("-- Listening on {0}, hit 'Enter' to stop...", device.Description);

                device.StartCapture();

                Console.ReadLine();

                device.StopCapture();

                device.Close();
            }
            catch (FormatException e)
            {
                Console.WriteLine("You have entered non-numeric characters");
                Console.ReadKey();
            }


            Console.WriteLine("\n\nPress Enter to exit");
            Console.ReadKey();
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            try {
                dashMac = PhysicalAddress.Parse(Properties.Settings.Default.DashMac.Replace("-", "").Replace(":", "").ToUpper());
            } catch (Exception e) {
                if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.DashMac))
                {
                    Console.WriteLine("Error: Could not parse dash mac address: " + e.Message);
                    return;
                }
            }

            CaptureDeviceList devices = CaptureDeviceList.Instance;

            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine("The following devices are available on this machine:");
            for (int i = 0; i < devices.Count; i++)
            {
                ICaptureDevice dev = devices[i];
                Console.WriteLine($"{i}: {dev.Description}");
            }

            ICaptureDevice device = devices[Properties.Settings.Default.InterfaceIndex];

            device.OnPacketArrival += device_OnPacketArrival;
            device.Open(DeviceMode.Promiscuous, ReadTimeoutMilliseconds);
            device.StartCapture();
            Console.WriteLine($"-- Listening on {Properties.Settings.Default.InterfaceIndex}, hit 'Enter' to stop...");
            Console.ReadLine();
            device.StopCapture();
            device.Close();
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Starts the target manager thread.
        /// </summary>
        public void Start()
        {
            Trace.WriteLine("starting communications manager");

            if (!Program.privateNetwork)
            {
                // get the packet capture device
                CaptureDeviceList devices = CaptureDeviceList.Instance;

                capDevice = devices[Program.interfaceToUse];
                Trace.WriteLine("using [" + capDevice.Description + "] for network capture");

                capDevice.OnPacketArrival += capDevice_OnPacketArrival;

                if (capDevice is WinPcapDevice)
                {
                    WinPcapDevice winPcap = capDevice as WinPcapDevice;
                    winPcap.Open(OpenFlags.Promiscuous | OpenFlags.NoCaptureLocal | OpenFlags.MaxResponsiveness, readTimeoutMilliseconds);
                }
                else if (capDevice is LibPcapLiveDevice)
                {
                    LibPcapLiveDevice livePcapDevice = capDevice as LibPcapLiveDevice;
                    livePcapDevice.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
                }
                else
                {
                    throw new InvalidOperationException("unknown device type of " + capDevice.GetType().ToString());
                }

                capDevice.StartCapture();
            }

            // start loop
            runThread = true;
            commMgrThread.Start();
        }
Ejemplo n.º 31
0
 public void Start()
 {
     dataBuffer = new List<string>();
     devices = CaptureDeviceList.Instance;
     if (devices.Count < 1)
     {
         comboBox1.Enabled = false;
         button1.Enabled = false;
     }
     else
     {
         devicesNames = new string[devices.Count];
         int i = 0;
         foreach (ICaptureDevice dev in devices)
         {
             string str = dev.ToString().Substring(dev.ToString().IndexOf("FriendlyName"));
             if (str.Contains("Gateway"))
             {
                 str = str.Substring(0, str.IndexOf("Gateway") - 1);
                 str = str.Substring(str.IndexOf(' ') + 1);
             }
             else
             {
                 str = str.Substring(str.IndexOf(' ') + 1);
                 str = str.Substring(0, str.IndexOf("Description") - 1);
             }
             comboBox1.Items.Add(str);
             File.Create(str + ".dat");
             devicesNames[i] = str;
             i++;
         }
         comboBox1.SelectedItem = comboBox1.Items[0];
         label2.Text = "";
         panel1.Focus();
     }
 }
Ejemplo n.º 32
0
 public Form1()
 {
     InitializeComponent();
     f       = new Form5();
     ip_list = new List <IPAddress>();
     my_ips  = new List <IPAddress>();
     // вывод всех имеющихся устройств
     list = CaptureDeviceList.Instance;
     foreach (ICaptureDevice i in list)
     {
         string name = i.Friendly();
         name = name.Replace("interface:", "");
         if (name != "")
         {
             comboBox1.Items.Add(name);
         }
     }
     comboBox1.Text = comboBox1.Items[0].ToString();
     label2.BringToFront();
     label3.BringToFront();
     label4.BringToFront();
     label5.BringToFront();
     button1.FlatAppearance.BorderSize = 2;
 }
Ejemplo n.º 33
0
        public frmCapture()
        {
            InitializeComponent();

            //Bing Map is supposed to be the fastest Map Provider
            gMap.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;

            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;

            //get the list of devices
            devices = CaptureDeviceList.Instance;

            //make sure that there is at least one device
            if (devices.Count < 1)
            {
                MessageBox.Show("no Capture Devices Found!");
                Application.Exit();
            }

            //add devices to the combo box
            foreach (ICaptureDevice dev in devices)
            {
                cmbDevices.Items.Add(dev.Description);
            }

            //get the third device and display in combo box
            device          = devices[0];
            cmbDevices.Text = device.Description;

            //register our handler function to the packet arrival event
            device.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);

            int readTimeoutMilliseconds = 1000;

            device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
        }
Ejemplo n.º 34
0
        public ToolUI()
        {
            InitializeComponent();

            //Change the icon and add the version to the title
            Icon  = Properties.Resources.iw4sp_1;
            Text += " " + Assembly.GetExecutingAssembly().GetName().Version;

            //Device listing
            try
            {
                //Get devices
                captureDevices = SharpPcap.CaptureDeviceList.Instance;

                //Add devices to the list
                foreach (ICaptureDevice captureDevice in captureDevices)
                {
                    Int32 index = deviceList.Items.Add(captureDevice);

                    if (captureDevice.Description == Settings.Default.CaptureDevice)
                    {
                        deviceList.SelectedIndex = index;
                    }
                }

                //Select the first device if nothing is selected
                if (deviceList.SelectedIndex == -1 && deviceList.Items.Count > 0)
                {
                    deviceList.SelectedIndex = 0;
                }
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 35
0
        public MainWindow()
        {
            InitializeComponent();

            CaptureDeviceList oCaptureDeviceList = new CaptureDeviceList();

            MyCaptureDevice = oCaptureDeviceList[0];
            MyCaptureDevice.SetCaptureListener(this);
            MyCaptureDevice.PrepareCapture(800, 600, 30.0f);

            INyARMarkerSystemConfig oMarkerSystemConfig = new NyARMarkerSystemConfig(800, 600);

            this.ARMarkerSystem = new NyARD3dMarkerSystem(oMarkerSystemConfig);
            this.ARCameraSensor = new NyARDirectShowCamera(MyCaptureDevice);

            this.MarkerID_Hiro  = this.ARMarkerSystem.addARMarker(AR_CODE_FILE1, 16, 25, 80);
            this.MarkerID_KanJi = this.ARMarkerSystem.addARMarker(AR_CODE_FILE2, 16, 25, 80);
            this.MarkerID_VTT   = this.ARMarkerSystem.addARMarker(AR_CODE_FILE3, 16, 25, 80);

            this.Loaded += MainWindow_Loaded;

            this.BtnPauseZm.Click += BtnPauseZm_Click;
            this.BtnStartZm.Click += BtnStartZm_Click;
        }
Ejemplo n.º 36
0
        /*private static void device_OnPcapStatistics(object sender, SharpPcap.WinPcap.StatisticsModeEventArgs e)
        {
            Console.WriteLine("bytes : {0}", e.Statistics.RecievedBytes);
            /*if (sender.Equals(rtChartPlotter.Form1.deviceMasterSent))
                devicesPacketLengthS[0] += e.Statistics.RecievedBytes;
            else if (sender.Equals(deviceMasterRecv))
                devicesPacketLengthR[0] += e.Statistics.RecievedBytes;

            if (sender.Equals(device1Sent))
                devicesPacketLengthS[1] += e.Statistics.RecievedBytes;
            else if (sender.Equals(device1Recv))
                devicesPacketLengthR[1] += e.Statistics.RecievedBytes;

            else if (sender.Equals(device2Sent))
                devicesPacketLengthS[2] += e.Statistics.RecievedBytes;
            else if (sender.Equals(device2Recv))
                devicesPacketLengthR[2] += e.Statistics.RecievedBytes;

            else if (sender.Equals(device3Sent))
                devicesPacketLengthS[3] += e.Statistics.RecievedBytes;
            else if (sender.Equals(device3Recv))
                devicesPacketLengthR[3] += e.Statistics.RecievedBytes;
        }*/
        private void Form1_Load(object sender, EventArgs e)
        {
            lines = File.ReadAllLines(@"c:\dinjter.csv").Select(a => a.Split(','));
            csv = from line in lines select (from piece in line select piece.Split(',')).ToArray();

            textboxStream = new TextBoxStreamWriter(textBox1);
            Console.SetOut(textboxStream);

            // Volt meter stub.
            textBox10.Text = "0.00 V";

            // Retrieve the device list
            devices = CaptureDeviceList.New();

            // If no devices were found print an error
            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }
            //set limit on NumericUpDown box
            this.numericUpDown1.Maximum = devices.Count-1;

            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");

            // Print out the available network devices
            foreach (ICaptureDevice dev in devices)
                Console.WriteLine("{0}\n", dev.ToString());

            device = devices[2];
            device.OnPacketArrival +=
            new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device.StartCapture();
            Console.WriteLine("device started");
            // Assign selected device to each members

            deviceMasterSent = devices[deviceNumber];
            device1Sent = devices[deviceNumber];
            device2Sent = devices[deviceNumber];
            device3Sent = devices[deviceNumber];
            deviceMasterRecv = devices[deviceNumber];
            device1Recv = devices[deviceNumber];
            device2Recv = devices[deviceNumber];
            device3Recv = devices[deviceNumber];

            // Register our handler function to the
            // 'packet statistics' event
            deviceMasterSent.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            deviceMasterRecv.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device1Sent.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
            device1Recv.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
            device2Sent.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
            device2Recv.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
            device3Sent.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
            device3Recv.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);

            // Open the device for capturing
            deviceMasterSent.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            deviceMasterRecv.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device1Sent.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device1Recv.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device2Sent.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device2Recv.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device3Sent.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device3Recv.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

            // Set device filter policy
            //deviceMasterSent.Filter = "src net 161.246.73.99";
            //deviceMasterRecv.Filter = "dst net 161.246.73.99";
            device1Sent.Filter = "src net 192.168.137.21";
            device1Recv.Filter = "dst net 192.168.137.21";
            device2Sent.Filter = "src net 192.168.137.22";
            device2Recv.Filter = "dst net 192.168.137.22";
            device3Sent.Filter = "src net 192.168.137.23";
            device3Recv.Filter = "dst net 192.168.137.23";

            Console.WriteLine("-- Listening on {0}, [Initial listening device]",
                deviceMasterSent.Description);

            // Start the capturing process
            deviceMasterSent.StartCapture();
            deviceMasterRecv.StartCapture();
            device1Sent.StartCapture();
            device1Recv.StartCapture();
            device2Sent.StartCapture();
            device2Recv.StartCapture();
            device3Sent.StartCapture();
            device3Recv.StartCapture();

            //isDeviceOpen = true;
        }
Ejemplo n.º 37
0
 /// <summary>
 /// Basic constructor of this class
 /// </summary>
 public HttpPacketCapture()
 {
     devices = CaptureDeviceList.Instance;
     readyAssembleHttpPacket = new List<HttpPacket>();
     seqNumbers = new Queue<uint>();
 }
Ejemplo n.º 38
0
        private void Form1_Load(object sender, EventArgs e)
        {
            timeDelay = timer1.Interval;

            lines = File.ReadAllLines(@"c:\dinjter.csv").Select(a => a.Split(','));
            csv = from line in lines select (from piece in line select piece.Split(',')).ToArray();

            textboxStream = new TextBoxStreamWriter(textBox1);
            Console.SetOut(textboxStream);

            // Volt meter stub.
            textBox10.Text = "0.00 V";

            // Retrieve the device list
            devices = CaptureDeviceList.New();

            // If no devices were found print an error
            if (devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }
            //set limit on NumericUpDown box
            this.numericUpDown1.Maximum = devices.Count - 1;

            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");

            // Print out the available network devices
            foreach (ICaptureDevice dev in devices)
                Console.WriteLine("{0}\n", dev.ToString());

            device0s = devices[0];
            device0r = devices[0];
            device1s = devices[0];
            device1r = devices[0];
            device2s = devices[0];
            device2r = devices[0];
            device3s = devices[0];
            device3r = devices[0];

            device0s.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device1s.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device1r.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device2s.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device2r.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device3s.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);
            device3r.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival);

            device0s.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device1s.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device1r.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device2s.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device2r.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device3s.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device3r.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

            device0s.StartCapture();
            //device1s.StartCapture();
            //device1r.StartCapture();
            //device2s.StartCapture();
            //device2r.StartCapture();
            //device3s.StartCapture();
            //device3r.StartCapture();

            Console.WriteLine("device started");
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WhiteNoise.DeviceWorker"/> class.
        /// </summary>
        /// <param name='lazyLoad'>
        /// Bypass loading of device list on loading.
        /// </param>
        public DeviceWorker(bool lazyLoad = false)
        {
            _captureFileWriter = null;
            _file = new FileInfo("results.pcap");

            this.Devices = new List<string>();
            this.Filter = "ip and tcp";
            this.Timeout = 1000;
            this.Version = SharpPcap.Version.VersionString;

            if (!lazyLoad)
            {
                this._devices = CaptureDeviceList.Instance;

                // Make a pretty list of devices.
                for (int i = 0; i < this._devices.Count; i++)
                {
                    this.Devices.Add(
                        string.Format("{1}. {2}{0}",
                            Environment.NewLine,
                            i + 1,
                            this._devices[i].Description)
                        );
                }
            }

            this.WorkerReportsProgress = true;
            this.WorkerSupportsCancellation = true;
        }
Ejemplo n.º 40
0
        private void listupDevice(string rbtname)
        {
            try
            {
                comboBox1.Items.Clear();
                comboBox1.Items.Add("::::::::::::장 치 선 택::::::::::::");
                if (rbtname.Equals(ConstDef.RBT_TYPE_SIP))
                {
                    deviceList = CaptureDeviceList.Instance;
                    if (deviceList.Count != 0)
                    {
                        foreach (ICaptureDevice d in deviceList)
                        {
                            comboBox1.Items.Add(d.Description);
                        }

                        if (ctrl.ServerType != null && !ctrl.ServerType.Equals(ConstDef.NIC_SIP))
                        {
                            comboBox1.DroppedDown = true;
                        }

                        else if (ctrl.ServerType == null)
                        {
                            comboBox1.DroppedDown = true;
                        }
                    }
                }
                else
                {
                    string[] ports = SerialPort.GetPortNames();
                    if (ports.Length > 0)
                    {
                        foreach (string item in ports)
                        {
                            comboBox1.Items.Add(item);
                        }

                        if (ctrl.ServerType != null && ctrl.ServerType.Equals(ConstDef.NIC_SIP))
                        {
                            comboBox1.DroppedDown = true;
                        }
                        else if (ctrl.ServerType == null)
                        {
                            comboBox1.DroppedDown = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                OnWriteLog("장치선택 오류발생:"+ex.ToString());

            }
        }
Ejemplo n.º 41
0
        private void listupDevice(string rbtname)
        {
            try
            {
                nicform.comboBox1.Items.Clear();
                nicform.comboBox1.Items.Add("::::::::::::장 치 선 택::::::::::::");
                if (rbtname.Equals(ConstDef.RBT_TYPE_SIP))
                {
                    deviceList = CaptureDeviceList.Instance;
                    if (deviceList.Count != 0)
                    {
                        foreach (ICaptureDevice d in deviceList)
                        {
                            nicform.comboBox1.Items.Add(d.Description);
                        }

                        if (server_device != null && !server_type.Equals(ConstDef.NIC_SIP))
                        {
                            nicform.comboBox1.DroppedDown = true;
                        }

                        else if (server_device == null)
                        {
                            nicform.comboBox1.DroppedDown = true;
                        }
                    }
                }
                else
                {
                    serialport = new SerialPort();
                    string[] ports = SerialPort.GetPortNames();
                    if (ports.Length > 0)
                    {
                        foreach (string item in ports)
                        {
                            nicform.comboBox1.Items.Add(item);
                        }

                        if (server_device != null && server_type.Equals(ConstDef.NIC_SIP))
                        {
                            nicform.comboBox1.DroppedDown = true;
                        }
                        else if (server_device == null)
                        {
                            nicform.comboBox1.DroppedDown = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
Ejemplo n.º 42
0
        //主窗口加载时的一些初始化
        private void MyForm_Load(object sender, EventArgs e)
        {
            stopButton.Enabled = false;
            restartButton.Enabled = false;
            cancelRecombineButton.Enabled = false;
            showDataBox.BackColor = Color.White;
            Control.CheckForIllegalCrossThreadCalls = false;
            this.devices = CaptureDeviceList.Instance;
            deviceComboBox.Items.AddRange(this.devices.Select(g=>g.Description).ToArray());

            //使用c#的委托机制,过滤窗口点击确定后调用主窗口的startFilter函数
            this.FilterForm.startFilter += new DelegateStartFilter(startFilter);
        }
Ejemplo n.º 43
0
        public string Connect(string Device_Name)
        {
            int failCount = 0;
            string result = "";

            deviceList = CaptureDeviceList.Instance;
            foreach (ICaptureDevice item in deviceList)
            {
                if (item.Description.Equals(Device_Name))
                {
                    dev = item;
                    break;
                }
            }

            try
            {
                if (dev != null)
                {
                    dev.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
                    dev.Open(DeviceMode.Promiscuous, 500);
                    dev.Filter = "udp src port 5060";

                    try
                    {
                        dev.StartCapture();
                        //log("Packet capture Start!!");
                    }
                    catch (Exception ex1)
                    {
                        //log("capture fail");
                        failCount++;

                    }
                }
            }
            catch (Exception ex)
            {
                failCount++;
                //Logwriter(ex.ToString());
            }
            if (failCount == 0)
            {
                result = "Success";
            }
            else
            {
                result = "Fail";
            }
            return result;
        }