public static PacketDevice SelectDevice(IList <LivePacketDevice> allDevices) { // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; Console.Write((i + 1) + ". " + device.Name); if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (No description available)"); } } int deviceIndex = 0; do { Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):"); string deviceIndexString = Console.ReadLine(); if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); // Take the selected adapter PacketDevice selectedDevice = allDevices[deviceIndex - 1]; return(selectedDevice); }
private void CbInterfaces_SelectedIndexChanged(object sender, EventArgs e) { tbGatewayIp.Clear(); tbGatewayMac.Clear(); tbNetmask.Clear(); if (cbInterfaces.SelectedItem == null) { return; } if (_packetCommunicator != null) { _packetCommunicator.Dispose(); } var iface = _interfaces.Keys.ElementAt(cbInterfaces.SelectedIndex); try { _packetCommunicator = iface.Open(); } catch (Exception) { } if (_packetCommunicator == null) { MetroMessageBox.Show(this, "Network interface could not be opened.", "Interface Error", MessageBoxButtons.OK, MessageBoxIcon.Error, 120); cbInterfaces.SelectedItem = null; _currentInterface = null; return; } _currentInterface = iface; UpdateAddresses(iface, _interfaces[iface]); }
public NetworkCard(LivePacketDevice dev, int index) { // Save the device so we can open it later! device = dev; // Get the GUID string idStr = dev.Name.Remove(0, dev.Name.IndexOf('{')); foreach (string s in idStr.Split('-')) { if (s.Length == 13) { macstr = s.TrimEnd('}'); } } // Match to full NetworkCard info // from .NET classes foreach (var nic in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()) { if (nic.Id == idStr) { Interface = nic; break; } } // Did we find one? if (Interface == null && macstr == null) { throw new Exception("Invalid network device."); } }
/// <summary> /// Returns the <see cref="MacAddress"/> for a <see cref="LivePacketDevice"/> instance. /// The <see cref="MacAddress"/> is retrieved through using WMI. /// </summary> /// <param name="livePacketDevice">The <see cref="LivePacketDevice"/> instance.</param> /// <returns>The <see cref="MacAddress"/> of the <see cref="LivePacketDevice"/> instance.</returns> /// <exception cref="InvalidOperationException">When the <see cref="MacAddress"/> cannot be retrieved using WMI.</exception> private static MacAddress GetMacAddressWmi(this LivePacketDevice livePacketDevice) { string pnpDeviceId = livePacketDevice.GetPnpDeviceId(); string escapedPnpDeviceId = pnpDeviceId.Replace(@"\", @"\\"); ManagementScope scope = new ManagementScope(@"\\.\root\cimv2"); scope.Connect(); var searcher = new ManagementObjectSearcher(scope, new SelectQuery("SELECT MACAddress FROM Win32_NetworkAdapter WHERE PNPDeviceID='" + escapedPnpDeviceId + "'")); foreach (ManagementObject managementObject in searcher.Get()) { string macAddress = managementObject["MACAddress"] as string; if (string.IsNullOrEmpty(macAddress)) { throw new InvalidOperationException("No MAC Address for WMI instance with PNP Device ID: " + pnpDeviceId); } return(new MacAddress(macAddress)); } throw new InvalidOperationException("No MAC Address for WMI instance with PNP Device ID: " + pnpDeviceId); }
public void Select() { if (allDevices.Count == 0) { CLI.PrintQueueLog(Channel.Zero, "장치를 찾을 수 없습니다.", ConsoleColor.White); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; CLI.PrintQueueLog(Channel.Zero, (i + 1) + " (" + device.Description + ")", ConsoleColor.White); } int deviceIndex = 0; do { CLI.PrintQueueLog(Channel.Zero, "인터페이스 넘버 (1-" + allDevices.Count + "):", ConsoleColor.White); string deviceIndexString = Console.ReadLine(); if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); // Take the selected adapter selectedDevice = allDevices[deviceIndex - 1]; }
private void DetermineNetworkInterface(int numTries = 5) { //Detect all interfaces allDevices = LivePacketDevice.AllLocalMachine; //Try the allotted number of times if no interfaces detected if (allDevices.Count == 0) { if (numTries > 0) { DetermineNetworkInterface(--numTries); } } //list available interfaces in ComboBox else if (allDevices.Count > 0) { for (int i = 0; i != allDevices.Count; ++i) { int offsetForWindowsMachines = 16; LivePacketDevice device = allDevices[i]; if (device.Description != null) { cmbInterfaces.Items.Add(device.Description.Substring(offsetForWindowsMachines)); } else { cmbInterfaces.Items.Add("*** (No description available)"); } } } }
private void createListener() { IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { MessageBox.Show("No Network Interface Found! Please make sure WinPcap is properly installed."); return; } for (int i = 0; i != allDevices.Count; i++) { LivePacketDevice device = allDevices[i]; if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (Unknown)"); } } using (List <LivePacketDevice> .Enumerator enumerator = allDevices.ToList <LivePacketDevice>().GetEnumerator()) { while (enumerator.MoveNext()) { PacketDevice selectedDevice = enumerator.Current; new Thread(() => inEnumerator(selectedDevice)).Start(); } } }
private void winCDP_Load(object sender, EventArgs e) { try { // Retrieve the device list from the local machine allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { MessageBox.Show("No interfaces found! Make sure WinPcap is installed.", "Error", MessageBoxButtons.OK); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; if (device.Description != null) { adapterList.Items.Add(extractSubString('\'', device.Description.ToString()) + " [" + device.Name.ToString().Replace("rpcap://", "") + "]"); } else { adapterList.Items.Add(device.Name.ToString().Replace("rpcap://", "")); } } adapterList.SelectedIndex = 0; } catch (Exception) { } }
public CaptureForm() { //checkFirst(); InitializeComponent(); this.packetView.DoubleBuffered(true); rawPacketViewItem.Checked = true; deviceIndex = 0; defaultFilterField = ""; sensorAddress = "0.0.0.0"; filter = ""; packetBytes = new List <byte[]>(); packets = new List <Packet>(); cougarpackets = new List <CougarPacket>(); packetNumber = 0; captFlag = true; numThreads = 0; protocolRequested = false; attributeRequested = false; captureAndDumpRequested = captureAndDumpMenuItem.Checked; multiWindowDisplay = multiWindowDisplayMenuItem.Checked; rawPacketViewDesired = rawPacketViewItem.Checked; cfb = new Tools.CougarFilterBuilder("or", "or"); bvf = new ByteViewerForm(); System.IO.StreamReader readingFile = new System.IO.StreamReader(Directory.GetCurrentDirectory() + "\\default.txt"); string readingLine = readingFile.ReadLine(); string[] values = readingLine.Split('='); maxFilePackets = Int32.Parse(values[1].Replace("\n", "")); readingLine = readingFile.ReadLine(); values = readingLine.Split('='); sensorAddress = values[1].Replace("\n", ""); selectedDevice = null; }
//constructors public ARPListener(LivePacketDevice device) : base(device) { base.Filter = "arp"; _targets = new TargetList(); _gateways = new TargetList(); }
private void FormHome_Load(object sender, EventArgs e) { if (allDevices.Count == 0) { RadMessageBox.Show("No adapters found", title, MessageBoxButtons.OK, RadMessageIcon.Error, MessageBoxDefaultButton.Button1); } else { for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; if (device.Description != null) { RadListDataItem item = new RadListDataItem(); item.Text = device.Description; ddlNetworkAdapters.Items.Add(item); } else { RadListDataItem item = new RadListDataItem(); item.Text = "Unknown"; ddlNetworkAdapters.Items.Add(item); } } if (ddlNetworkAdapters.Items.Count > 0) { ddlNetworkAdapters.SelectedIndex = 0; } } }
private void refreshAdapters() { allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { Console.WriteLine("No interfaces found! Make sure WinPcap is installed."); return; } cmbAdapters.Items.Clear(); for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; cmbAdapters.Items.Add(device.Description); if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (No description available)"); } } cmbAdapters.SelectedIndex = 0; }
public StartWindow() { InitializeComponent(); //If there is no device if (allDevices.Count == 0) { cmbNetworkDevice.Items.Add("No interfaces found! Make sure WinPcap is installed."); return; } //Get devices name to combobox for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; if (device.Description != null) { cmbNetworkDevice.Items.Add((i + 1) + ". " + "(" + device.Description + ")"); } else { cmbNetworkDevice.Items.Add((i + 1) + ". " + "( Açıklama Yok )"); } } }
protected void OnPacketArrivaled(Packet packet, LivePacketDevice dev) { lock (ExtraInfos[dev.Name].QueueLock) { ExtraInfos[dev.Name].PacketQueue.Add(packet); } }
/// <summary> /// Gets device list on local machine /// </summary> /// <returns>names and descriptions of every device</returns> public static string GetDevices() { string st = string.Empty; allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { return("No interfaces found! Make sure WinPcap is installed."); } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; st += (i + 1) + ". " + device.Name + "\n\r"; if (device.Description != null) { st += " (" + device.Description + ")" + "\n\r"; } else { st += " (No description available)" + "\n\r"; } } return(st); }
public void Log(LivePacketDevice networkInterface) { Console.WriteLine($"{networkInterface.Name ?? "Name not found"}"); Console.WriteLine($"\t description : {networkInterface.Description ?? "Description not found"}"); Console.WriteLine((networkInterface.Attributes & DeviceAttributes.Loopback) == DeviceAttributes.Loopback ? "\t is loopback " : "\t is not loopback"); foreach (var deviceAddress in networkInterface.Addresses) { Console.WriteLine($"\t family : {deviceAddress.Address.Family}"); Console.WriteLine(deviceAddress.Address != null ? $"\t address : {deviceAddress.Address}" : "\t address not found"); Console.WriteLine(deviceAddress.Netmask != null ? $"\t netmask : {deviceAddress.Netmask}" : "\t netmask not found"); Console.WriteLine(deviceAddress.Broadcast != null ? $"\t brodcast : {deviceAddress.Broadcast}" : "\t brodcast not found"); Console.WriteLine(deviceAddress.Destination != null ? $"\t destination : {deviceAddress.Destination}" : "\t destination not found"); } Console.WriteLine(); }
private void WinEnum_Load(object sender, EventArgs e) { if (!IsAdministrator()) { ProcessStartInfo proc = new ProcessStartInfo(); proc.UseShellExecute = true; proc.WorkingDirectory = Environment.CurrentDirectory; proc.FileName = Application.ExecutablePath; proc.Verb = "runas"; try { Process.Start(proc); } catch { return; } Application.Exit(); } windowsVersions.Add("6.4", "Windows 10"); windowsVersions.Add("6.3", "Windows 8.1"); windowsVersions.Add("6.2", "Windows 8"); windowsVersions.Add("6.1", "Windows 7"); windowsVersions.Add("6.0", "Windows Vista"); windowsVersions.Add("5.2", "Windows XP Pro x64"); windowsVersions.Add("5.1", "Windows XP"); upnpTypes.Add("upnp:rootdevice"); upnpTypes.Add("urn:schemas-upnp-org:device:InternetGatewayDevice:1"); upnpTypes.Add("urn:schemas-upnp-org:service:WANPPPConnection:1"); upnpTypes.Add("urn:schemas-upnp-org:service:WANIPConnection:1"); upnpTypes.Add("urn:schemas-upnp-org:service:WANPPPConnection:1"); comboBox1.Items.Add("Router"); comboBox1.Items.Add("Media Server"); comboBox1.Items.Add("Media Player"); comboBox1.SelectedIndex = 0; for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; string ifaceIP = ""; for (int j = 0; j != device.Addresses.Count; ++j) { DeviceAddress address = device.Addresses[j]; if (address.Address.Family.ToString() == "Internet") { string[] addressParts = address.Address.ToString().Split(); ifaceIP = addressParts[1]; } } networkInterfaces.Items.Add(String.Format("{0} {2} {1}", ifaceIP.ToString(), device.Name, device.Description != null ? String.Format(" ({0})", device.Description) : "[nNo device description]")); } }
private void PaketYakala(String filtre = "ip") { for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; } selectedDevice = allDevices[deviceIndex - 1]; using (PacketCommunicator communicator = selectedDevice.Open(65536, // portion of the packet to capture // 65536 guarantees that the whole packet will be captured on all the link layers PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode 1000)) // read timeout { // Check the link layer. We support only Ethernet for simplicity. if (communicator.DataLink.Kind != DataLinkKind.Ethernet) { Console.WriteLine("This program works only on Ethernet networks."); return; } // Compile the filter using (BerkeleyPacketFilter filter = communicator.CreateFilter(filtre)) { // Set the filter communicator.SetFilter(filter); } label2.Text = selectedDevice.Description; // start the capture communicator.ReceivePackets(0, PacketHandler); } }
static void Main(string[] args) { /* DESCOMENTAR ESTO PARA TESTEAR PREGUNTAS * Pregunta p = new Pregunta { Id = "1", Titulo= "De que son las nuevas materias creadas por la Universidad de Binghamtom?", Opcion1= "Huracanes", Opcion2= "Tornados", Opcion3= "Tempestades" }; * // CargarPregunta(p, new List<int> { 0, 10, 0 }); * //var lista = BuscarPregunta("Cual de estas novelas no tuvo segunda parte?", "El jardin del Eden", "Don quijote", "Ensayo sobre la ceguera"); * // Retrieve the device list from the local machine * var resultado = BuscarPregunta("Cual de estos libros fue escrito por el argentino hernan vanoli?", "Una misma noche", "Pyongyang", "Ninguno de los dos"); * CargarPregunta(p, resultado);*/ IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { //Console.WriteLine("No interfaces found! Make sure WinPcap is installed."); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; /* Console.Write((i + 1) + ". " + device.Name); * if (device.Description != null) * Console.WriteLine(" (" + device.Description + ")"); * else * Console.WriteLine(" (No description available)");*/ } string s = "--------------Esperando preguntas--------------"; Console.WriteLine(s); int deviceIndex = 0; do { //Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):"); string deviceIndexString = "1"; if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); // Take the selected adapter PacketDevice selectedDevice = allDevices[deviceIndex - 1]; // Open the device using (PacketCommunicator communicator = selectedDevice.Open(65536, // portion of the packet to capture // 65536 guarantees that the whole packet will be captured on all the link layers PacketDeviceOpenAttributes.None, // promiscuous mode 1000)) // read timeout { // Console.WriteLine("Listening on " + selectedDevice.Description + "..."); // start the capture communicator.ReceivePackets(0, PacketHandler); } }
public PacketCommunicator OpenPcapDevice(string deviceId, int timeout) { LivePacketDevice selectedDevice = this.allinterfaces.Where(elem => elem.Name.Contains(deviceId)).First(); PacketCommunicator communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, timeout); return(communicator); }
private void btnSendPkt_Click(object sender, EventArgs e) { // Retrieve the device list from the local machine IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { Console.WriteLine("No interfaces found! Make sure WinPcap is installed."); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; Console.Write((i + 1) + ". " + device.Name); if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (No description available)"); } } }
protected void StartCapture(LivePacketDevice dev) { if (dev == null) { return; } ExtraInfos[dev.Name].BackgroundThreadStop = false; ExtraInfos[dev.Name].BackgroundThread = new Thread(BackgroundThread); ExtraInfos[dev.Name].BackgroundThread.Start(dev); ExtraInfos[dev.Name].BackgroundThread.IsBackground = true; ExtraInfos[dev.Name].CaptureCancellation = new CancellationTokenSource(); ThreadPool.QueueUserWorkItem(new WaitCallback(state => { CancellationToken token = (CancellationToken)state; // Open device using (PacketCommunicator communicator = dev.Open( 65535, PacketDeviceOpenAttributes.Promiscuous, 250 )) { while (!token.IsCancellationRequested) { communicator.ReceivePackets(200, packet => { OnPacketArrivaled(packet, dev); }); } } }), ExtraInfos[dev.Name].CaptureCancellation.Token); }
static void Main(string[] args) { // Retrieve the device list from the local machine IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { Console.WriteLine("No interfaces found! Make sure WinPcap is installed."); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; Console.Write((i + 1) + ". " + device.Name); if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (No description available)"); } } int deviceIndex = 0; do { Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):"); string deviceIndexString = Console.ReadLine(); if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); // Take the selected adapter PacketDevice selectedOutputDevice = allDevices[deviceIndex - 1]; // Open the output adapter using ( PacketCommunicator communicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000)) { // Compile and set the filter communicator.SetFilter("tcp"); // Put the interface in statstics mode communicator.Mode = PacketCommunicatorMode.Statistics; Console.WriteLine("TCP traffic summary:"); // Start the main loop communicator.ReceiveStatistics(0, StatisticsHandler); } }
private void CreateListener() { IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { Debug.WriteLine("No Network Interface Found! Please make sure WinPcap is properly installed."); return; } for (int i = 0; i != allDevices.Count; i++) { LivePacketDevice device = allDevices[i]; if (device.Description != null) { Debug.WriteLine(" (" + device.Description + ")"); } else { Debug.WriteLine(" (Unknown)"); } } using (List <LivePacketDevice> .Enumerator enumerator = allDevices.ToList <LivePacketDevice>().GetEnumerator()) { while (enumerator.MoveNext()) { PacketDevice selectedDevice = enumerator.Current; if (selectedDevice.Attributes == DeviceAttributes.Loopback) { continue; } new Thread(delegate() { try { using (PacketCommunicator communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)) { if (communicator.DataLink.Kind != DataLinkKind.Ethernet) { Debug.WriteLine("This program works only on Ethernet networks."); } else { using (BerkeleyPacketFilter filter = communicator.CreateFilter("ip and udp")) { communicator.SetFilter(filter); } Console.WriteLine("Capturing on " + selectedDevice.Description + "..."); communicator.ReceivePackets(0, new HandlePacket(photonPacketHandler.PacketHandler)); } } } catch (NotSupportedException ex) { Console.WriteLine($"Error listening on {selectedDevice.Description} because of {ex.Message}. Skipping this device. If it still works you can ignore this"); } }).Start(); } } }
public ProtectionOptions(LivePacketDevice device) { this.device = device; DeviceAddress ip = device.Addresses.FirstOrDefault(address => address.Address.Family == SocketAddressFamily.Internet); this.localIP = ip != null ? new IpV4Address(ip.GetIP()) : IpV4Address.Zero; this.Reacting = new IgnoreScanningReaction(); }
public void RegisterRAWInterface(LivePacketDevice iface) { Ethernet enet = new Ethernet(iface); _pupPacketInterface = enet; _rawPacketInterface = enet; _pupPacketInterface.RegisterRouterCallback(RouteIncomingLocalPacket); }
private void createListener() { IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { MessageBox.Show("No interfaces found! Make sure WinPcap is installed."); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (No description available)"); } } foreach (PacketDevice selectedDevice in allDevices.ToList()) { // Open the device Thread t = new Thread(() => { using (PacketCommunicator communicator = selectedDevice.Open(65536, // portion of the packet to capture // 65536 guarantees that the whole packet will be captured on all the link layers PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode 1000)) // read timeout { // Check the link layer. We support only Ethernet for simplicity. if (communicator.DataLink.Kind != DataLinkKind.Ethernet) { Console.WriteLine("This program works only on Ethernet networks."); return; } // Compile the filter using (BerkeleyPacketFilter filter = communicator.CreateFilter("ip and udp")) { // Set the filter communicator.SetFilter(filter); } Console.WriteLine("Listening on " + selectedDevice.Description + "..."); // start the capture communicator.ReceivePackets(0, photonPacketHandler.PacketHandler); } }); t.Start(); } }
public void ReceivePackets() { // Retrieve the device list from the local machine IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; // Find the NPF device of the TAP interface PacketDevice selectedDevice = null; for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; if (device.Name.Contains(Guid)) { selectedDevice = device; break; } } if (selectedDevice == null) { Initialized.Set(); Global.ShowTrayTip("Byte Counter", "Interface " + Name + " not captured by WinPcap.", System.Windows.Forms.ToolTipIcon.Warning); Global.WriteLog("Byte Counter: Interface " + Name + " not captured by WinPcap."); return; } try { using (communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.MaximumResponsiveness, 1000)) { Global.WriteLog("Byte Counter: Listening on " + Name + "..."); communicator.SetFilter("((ether dst " + ifHardwareAddressString + " or ether src " + ifHardwareAddressString + ") and ip and (tcp or udp))"); Initialized.Set(); communicator.ReceivePackets(0, (packet) => { if (!threadActive.IsSet) { communicator.Break(); return; } Table.CheckPacket(packet, ifHardwareAddress); }); } } catch (Exception e) { if (threadActive.IsSet) { threadActive.Reset(); Global.WriteLog("Byte Counter: Could not capture traffic from " + Name); if (Global.Config.Gadget.Debug) { Global.WriteLog(e.ToString()); } Global.ShowTrayTip("Byte Counter", "Could not capture traffic from " + Name, System.Windows.Forms.ToolTipIcon.Warning); } } }
static void Main(string[] args) { // Lista urządzeń IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { Console.WriteLine("No interfaces found! Make sure WinPcap is installed."); return; } // Wypisuje urządzenia for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; Console.WriteLine((i + 1) + ". " + device.Description); if (device.Description == null) { Console.Write((i + 1) + ". " + device.Name); Console.WriteLine(" (No description available)"); } } int deviceIndex = 0; //wprowadzanie numeru urzadzenia do { Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):"); string deviceIndexString = Console.ReadLine(); if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); PacketDevice selectedDevice = allDevices[deviceIndex - 1]; // Ustawiamy komunikator do przechwytywania z urządzenia using (PacketCommunicator communicator = selectedDevice.Open(65536, // portion of the packet to capture // 65536 guarantees that the whole packet will be captured on all the link layers PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode 1000)) // read timeout { // Filter Console.WriteLine("If you want, you can specify filter now"); using (BerkeleyPacketFilter filter = communicator.CreateFilter(Console.ReadLine())) { communicator.SetFilter(filter); } Console.WriteLine("Listening on " + selectedDevice.Description + "..."); // przechwytywanie communicator.ReceivePackets(0, PacketHandler); } }
static void SendPackets() { // Retrieve the device list from the local machine IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; if (allDevices.Count == 0) { Console.WriteLine("No interfaces found! Make sure WinPcap is installed."); return; } // Print the list for (int i = 0; i != allDevices.Count; ++i) { LivePacketDevice device = allDevices[i]; Console.Write((i + 1) + ". " + device.Name); if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (No description available)"); } } int deviceIndex = 0; do { Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):"); string deviceIndexString = Console.ReadLine(); if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); PacketDevice selectedDevice = allDevices[deviceIndex - 1]; using (PacketCommunicator communicator = selectedDevice.Open(1, // name of the device PacketDeviceOpenAttributes.MaximumResponsiveness, // promiscuous mode 1000)) // read timeout { Packet pack = BuildPackets.BuildVLanTaggedFramePacket(); PacketSendBuffer packbuffer = new PacketSendBuffer(1526000); for (int i = 0; i != 1000; ++i) { packbuffer.Enqueue(pack); } for (int i = 0; i != 1000; ++i) { communicator.Transmit(packbuffer, false); } } }
private long _timePerRun = 60000; //1min #endregion Fields #region Constructors //constructors public CAMOverflowSender(LivePacketDevice device, int entryCount) { _device = device; _entries = new List<Tuple<MacAddress, IpV4Address>>(); _random = new Random(); EntryCount = entryCount; _bgWorker = new BackgroundWorker(); _bgWorker.WorkerSupportsCancellation = true; _bgWorker.DoWork += new DoWorkEventHandler(DoWork); InitializePackets(); }
// Filter syntax: https://www.winpcap.org/docs/docs_40_2/html/group__language.html public void Listen(LivePacketDevice adapter, String filter, int count) { this.adapter = adapter; using (PacketCommunicator communicator = adapter.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)) { try { communicator.SetFilter(filter); } catch (Exception e) { MessageBox.Show(null, e.Message, "Filter Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } communicator.ReceivePackets(count, PacketHandler); } }
public SnifferParams(LivePacketDevice device, String filter, int count) { this.device = device; this.filter = filter; this.count = count; }
//constructors public ARPSender(LivePacketDevice device) { _device = device; _bgWorker = new BackgroundWorker(); _bgWorker.DoWork += new DoWorkEventHandler(DoWork); }
public CDPWorkerObject(LivePacketDevice sd, CALLBACK cb) { try { selectedDevice = sd; callBack = cb; communicator = selectedDevice.Open(512, PacketDeviceOpenAttributes.Promiscuous, 1000); capturedPacket = null; } catch (Exception) { } }
static void msearch_response_spoof(LivePacketDevice selectedDevice, string msearch_string, string sourceIP, ushort sourcePort, string destIP, ushort destPort, string destMac) { byte[] temp = System.Text.Encoding.ASCII.GetBytes(msearch_string); EthernetLayer ethernetLayer = new EthernetLayer { Source = LivePacketDeviceExtensions.GetMacAddress(selectedDevice), Destination = new MacAddress(destMac), EtherType = EthernetType.None, }; var options = IpV4FragmentationOptions.DoNotFragment; IpV4Layer ipV4Layer = new IpV4Layer { Source = new IpV4Address(sourceIP), CurrentDestination = new IpV4Address(destIP), Fragmentation = new IpV4Fragmentation(options,0), HeaderChecksum = null, Identification = 0, Options = IpV4Options.None, Protocol = null, Ttl = 64, TypeOfService = 0, }; UdpLayer udpLayer = new UdpLayer { SourcePort = sourcePort, DestinationPort = destPort, Checksum = null, CalculateChecksumValue = true, }; PayloadLayer payloadLayer = new PayloadLayer { Data = new Datagram(temp), }; PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, udpLayer, payloadLayer); using (PacketCommunicator communicator = selectedDevice.Open(69559, PacketDeviceOpenAttributes.Promiscuous, 1000)) // read timeout { communicator.SendPacket(builder.Build(DateTime.Now)); } }
private void button1_Click(object sender, EventArgs e) { if (networkInterfaces.SelectedIndex == -1) { MessageBox.Show("Please select a network interface first.", "Select a network interface", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } else { status = true; button1.Enabled = false; button2.Enabled = true; networkInterfaces.Enabled = false; timer1.Interval = trackBar1.Value; allSystemsOnline(); if (disableWebServer.Checked != true) { if (!IsAdministrator()) { string current_username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; AddAddress(deviceDescURL.Text.Replace(sourceIP.Text, "*"),current_username); AddAddress(scpdURL.Text.Replace(sourceIP.Text, "*"), current_username); removeFromNetSh.Add(deviceDescURL.Text.Replace(sourceIP.Text, "*")); removeFromNetSh.Add(scpdURL.Text.Replace(sourceIP.Text, "*")); } try { ws = new WebServer(SendResponse, deviceDescURL.Text.Replace(sourceIP.Text, "*")); if (deviceFromFile != null) { ws.device = deviceFromFile; } ws.Run(); scpdWs = new WebServer(SendSCPDResponse, scpdURL.Text.Replace(sourceIP.Text, "*")); scpdWs.Run(); if (ws.ErrorMessage != "") { MessageBox.Show(ws.ErrorMessage); } else { hitCounter.Text = "Web Server Started"; } } catch { MessageBox.Show("Failed to start web servers. Something already on port:"+webserverPort.Text+"?"); } } else { hitCounter.Text = "Using custom URL"; } timer1.Start(); timer1_Tick(null, null); timer2.Start(); timer2_Tick(null, null); device = allDevices[networkInterfaces.SelectedIndex]; if (!bw.IsBusy) { bw.RunWorkerAsync(); } else { bw.CancelAsync(); } } }
public void StartCapture(PcapDotNet.Core.HandlePacket PacketHandler, LivePacketDevice device) { _device = device; StartCapture(PacketHandler); }
public Listener(LivePacketDevice device, String filter) : this(device) { _filter = filter; }
public Listener(LivePacketDevice device) : this() { _device = device; }
void tsbStop_Click(object sender, EventArgs e) { stop = true; paused = false; comm.Break(); comm.Dispose(); device = null; comm = null; tsbStart.Enabled = tscbNet.Enabled = true; tsbPause.Enabled = tsbStop.Enabled = false; this.Text = "Ostara - Stopped"; }
void tsbStart_Click(object sender, EventArgs e) { stop = false; tsbStart.Enabled = tscbNet.Enabled = false; tsbPause.Enabled = tsbStop.Enabled = true; this.Text = "Ostara - Logging"; if (paused) { paused = false; return; } if (Settings.I.ClearOnStart) flvPackets.ClearObjects(); packets = new Queue<PacketClass>(); clientCrypt = new Dictionary<ushort, Cryption.Client>(); serverCrypt = new Dictionary<ushort, Cryption.Server>(); int ni = tscbNet.SelectedIndex; device = LivePacketDevice.AllLocalMachine[ni]; comm = device.Open(65536, PacketDeviceOpenAttributes.None, 500); comm.SetFilter(Ports.I.Filter); foreach (var a in device.Addresses) { if (a.Address.Family == SocketAddressFamily.Internet) { address = ((IpV4SocketAddress)a.Address).Address.ToValue(); break; } } Task.Run(() => { GetPackets(); }); }
//constructors public ArpDosSender(LivePacketDevice device, Target Gateway) { _device = device; _gateway = Gateway; _ownMacAddr = _device.GetMacAddress(); _bgWorker = new BackgroundWorker(); _bgWorker.WorkerSupportsCancellation = true; _bgWorker.DoWork += new DoWorkEventHandler(DoWork); _targets = new List<Target>(); }
//constructors public ArpPoisoner(LivePacketDevice device, Target Gateway) { _device = device; _gateway = Gateway; _ownMacAddr = _device.GetMacAddress(); _bgWorker = new BackgroundWorker(); _bgWorker.WorkerSupportsCancellation = true; _bgWorker.DoWork += new DoWorkEventHandler(DoWork); _targets = new List<Target>(); _dnsSpoofingList = new DNSspoofingList(); _forwardingListener = new Listener.Listener(device, "ip and ( udp or tcp) and ether dst " + _ownMacAddr.ToString() + " and not host " + _device.getIpV4Address().Address.ToString()); _forwardingListener.StartCapture(Forwarder); }