コード例 #1
0
ファイル: xbs_sniffer.cs プロジェクト: Ch0wW/XBSlink
        public xbs_sniffer(ICaptureDevice dev, bool use_special_mac_filter, List<PhysicalAddress> filter_special_macs, bool only_forward_special_macs, xbs_node_list node_list, xbs_nat NAT, GatewayIPAddressInformationCollection gateways, bool exclude_gateway_ips)
        {
            this.NAT = NAT;
            this.pdev_filter_use_special_macs = use_special_mac_filter;
            if (filter_special_macs!=null)
                this.pdev_filter_special_macs = filter_special_macs;
            this.pdev_filter_only_forward_special_macs = only_forward_special_macs;
            this.pdev_filter_exclude_gatway_ips = exclude_gateway_ips;
            create_gateway_filter(gateways);
            injected_macs_hash.Capacity = 40;
            sniffed_macs_hash.Capacity = 10;
            sniffed_macs.Capacity = 10;

            this.node_list = node_list;

            if (!(dev is SharpPcap.LibPcap.LibPcapLiveDevice))
                throw new ArgumentException("pcap caputure device is not a LibPcapLiveDevice");
            this.pdev = (SharpPcap.LibPcap.LibPcapLiveDevice)dev;
            pdev.OnPacketArrival +=
                new PacketArrivalEventHandler(OnPacketArrival);
            pdev.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            setPdevFilter();

            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT && pdev is SharpPcap.WinPcap.WinPcapDevice)
                ((SharpPcap.WinPcap.WinPcapDevice)pdev).MinToCopy = 10;

            xbs_messages.addInfoMessage(" - sniffer created on device " + pdev.Description, xbs_message_sender.SNIFFER);

            dispatcher_thread = new Thread(new ThreadStart(dispatcher));
            dispatcher_thread.IsBackground = true;
            dispatcher_thread.Priority = ThreadPriority.AboveNormal;
            dispatcher_thread.Start();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Ch0wW/XBSlink
        private void Form1_Load(object sender, EventArgs e)
        {
            // globally turn off Proxy auto detection
            WebRequest.DefaultWebProxy = null;

            node_list = new xbs_node_list();
            cloudlist = new xbs_cloudlist();
            upnp = new xbs_upnp();
            NAT = new xbs_nat();

            initializeCloudListView();

            timer_messages.Start();
            form1_width = this.Width;
            ShowVersionInfoMessages();

            textBox_local_Port.Text = xbs_udp_listener.standard_port.ToString();
            textBox_remote_port.Text = xbs_udp_listener.standard_port.ToString();

            initializeLocalIPList();
            initializeTrayIcon();
            initWithRegistryValues();
            initializeAboutWindow();

            tabControl1.SelectedTab = tabPage_settings;
            autoswitch_on_chat_message = checkBox_chatAutoSwitch.Checked;

            if (checkBox_showNewsFeed.Checked)
                loadNewsFeed(textBox_newsFeedUri.Text);
        }
コード例 #3
0
ファイル: xbs_udp_listener.cs プロジェクト: Ch0wW/XBSlink
        private bool initialize(IPAddress ip_endpoint, int port, xbs_node_list nl)
        {
            this.node_list = nl;
            dispatcher_thread = new Thread(new ThreadStart(dispatcher));
            dispatcher_thread.IsBackground = true;
            dispatcher_thread.Priority = ThreadPriority.AboveNormal;
            dispatcher_thread.Start();
            dispatcher_thread_out = new Thread(new ThreadStart(dispatcher_out));
            dispatcher_thread_out.IsBackground = true;
            dispatcher_thread_out.Priority = ThreadPriority.AboveNormal;
            dispatcher_thread_out.Start();

            udp_socket_port = port;
            local_endpoint = new IPEndPoint(ip_endpoint, udp_socket_port);

            udp_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            try
            {
                udp_socket.Bind(local_endpoint);
            }
            catch (SocketException)
            {
                throw new Exception("an error occured while initializing the UDP socket.\r\nPlease see the messages tab.");
            }
            udp_socket.ReceiveTimeout = 1000;
            receive_thread = new Thread( new ThreadStart(udp_receiver) );
            receive_thread.IsBackground = true;
            receive_thread.Priority = ThreadPriority.AboveNormal;
            receive_thread.Start();

            xbs_messages.addInfoMessage(" * initialized udp listener on port " + port, xbs_message_sender.UDP_LISTENER);
            return true;
        }
コード例 #4
0
ファイル: xbs_udp_listener.cs プロジェクト: Ch0wW/XBSlink
 public xbs_udp_listener( IPAddress ip_endpoint, int port, xbs_node_list nl)
 {
     initialize(ip_endpoint, port, nl);
 }
コード例 #5
0
ファイル: xbs_udp_listener.cs プロジェクト: Ch0wW/XBSlink
 public xbs_udp_listener(xbs_node_list nl)
 {
     initialize(IPAddress.Any, xbs_udp_listener.standard_port, nl);
 }
コード例 #6
0
ファイル: CommandLine.cs プロジェクト: tbutter/XBSlink
        private void start_engine()
        {
            if (option_upnp)
            {
                discover_upnp();
            }
            LibPcapLiveDevice pdev = loadCaptureDevice(option_capture_device);

            if (pdev == null)
            {
                xbs_messages.addInfoMessage("!! ERROR - could not load capture device with name \"" + option_capture_device + "\"", xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR);
                close_app(-2);
            }

            NAT       = new xbs_nat();
            node_list = new xbs_node_list();
            node_list.notify_on_new_node = false;
            if (option_local_port == 0)
            {
                option_local_port = xbs_udp_listener.standard_port;
            }
            GatewayIPAddressInformationCollection local_gateways = xbs_console_app.getGatewaysForBindIP(option_local_ip);

            try
            {
                udp_listener = new xbs_udp_listener(option_local_ip, option_local_port, node_list);
            }
            catch (Exception e)
            {
                xbs_messages.addInfoMessage("!! ERROR opening UDP port " + option_local_port, xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR);
                xbs_messages.addInfoMessage(e.Message, xbs_message_sender.GENERAL);
                close_app(-7);
            }

            try
            {
                if (option_upnp && upnp.isUPnPavailable())
                {
                    external_ip = upnp.upnp_getPublicIP();
                    upnp.upnp_create_mapping(Mono.Nat.Protocol.Udp, udp_listener.udp_socket_port, udp_listener.udp_socket_port);
                }
            }
            catch (Exception)
            {
                xbs_messages.addInfoMessage("!! UPnP port mapping failed", xbs_message_sender.GENERAL, xbs_message_type.ERROR);
            }
            if (external_ip == null)
            {
                external_ip = xbs_upnp.getExternalIPAddressFromWebsite();
            }
            IPAddress local_node_ip = (external_ip == null) ? option_local_ip : external_ip;

            node_list.local_node = new xbs_node(local_node_ip, udp_listener.udp_socket_port);
            if (option_nickname != null)
            {
                node_list.local_node.nickname = option_nickname;
            }

            sniffer = new xbs_sniffer(pdev, false, null, false, node_list, NAT, local_gateways, true);
            sniffer.start_capture();

            if (ExceptionMessage.ABORTING)
            {
                close_app(-10);
            }

            if (option_cloudserver == null)
            {
                option_cloudserver = xbs_cloudlist.DEFAULT_CLOUDLIST_SERVER;
            }

            if (option_cloudname != null)
            {
                if (option_password == null)
                {
                    option_password = "";
                }
                if (option_cloudname.Length >= xbs_cloudlist.MIN_CLOUDNAME_LENGTH)
                {
                    try
                    {
                        cloudlist.JoinOrCreateCloud(option_cloudserver, option_cloudname, option_maxnodes.ToString(), option_password, node_list.local_node.ip_public, node_list.local_node.port_public, node_list.local_node.nickname, xbs_upnp.isPortReachable, xbs_settings.xbslink_version);
                    }
                    catch (Exception e)
                    {
                        xbs_messages.addInfoMessage("!! ERROR connecting to cloud " + option_cloudname, xbs_message_sender.GENERAL, xbs_message_type.ERROR);
                        xbs_messages.addInfoMessage(e.Message, xbs_message_sender.GENERAL, xbs_message_type.ERROR);
                    }
                }
                else
                {
                    xbs_messages.addInfoMessage("!! ERROR - cloudname is too short. " + xbs_cloudlist.MIN_CLOUDNAME_LENGTH + " chars minimum", xbs_message_sender.GENERAL, xbs_message_type.ERROR);
                    close_app(-12);
                }
            }

            main_engine_loop();
        }
コード例 #7
0
ファイル: CommandLine.cs プロジェクト: Ch0wW/XBSlink
 private void initialize()
 {
     node_list = new xbs_node_list();
     udp_listener = new xbs_udp_listener(node_list);
     upnp = new xbs_upnp();
 }
コード例 #8
0
ファイル: CommandLine.cs プロジェクト: Ch0wW/XBSlink
        private void start_engine()
        {
            if (option_upnp)
                discover_upnp();
            LibPcapLiveDevice pdev = loadCaptureDevice(option_capture_device);
            if (pdev == null)
            {
                xbs_messages.addInfoMessage("!! ERROR - could not load capture device with name \"" + option_capture_device + "\"", xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR);
                close_app(-2);
            }

            NAT = new xbs_nat();
            node_list = new xbs_node_list();
            node_list.notify_on_new_node = false;
            if (option_local_port == 0)
                option_local_port = xbs_udp_listener.standard_port;
            GatewayIPAddressInformationCollection local_gateways = xbs_console_app.getGatewaysForBindIP(option_local_ip);
            try
            {
                udp_listener = new xbs_udp_listener(option_local_ip, option_local_port, node_list);
            }
            catch (Exception e)
            {
                xbs_messages.addInfoMessage("!! ERROR opening UDP port " + option_local_port, xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR);
                xbs_messages.addInfoMessage(e.Message, xbs_message_sender.GENERAL);
                close_app(-7);
            }

            try
            {
                if (option_upnp && upnp.isUPnPavailable())
                {
                    external_ip = upnp.upnp_getPublicIP();
                    upnp.upnp_create_mapping(Mono.Nat.Protocol.Udp, udp_listener.udp_socket_port, udp_listener.udp_socket_port);
                }
            }
            catch (Exception)
            {
                xbs_messages.addInfoMessage("!! UPnP port mapping failed", xbs_message_sender.GENERAL, xbs_message_type.ERROR);
            }
            if (external_ip == null)
                external_ip = xbs_upnp.getExternalIPAddressFromWebsite();                        
            IPAddress local_node_ip = (external_ip == null) ? option_local_ip : external_ip;
            node_list.local_node = new xbs_node(local_node_ip, udp_listener.udp_socket_port);
            if (option_nickname!=null)
                node_list.local_node.nickname = option_nickname;

            sniffer = new xbs_sniffer(pdev, false, null, false, node_list, NAT, local_gateways, true);
            sniffer.start_capture();

            if (ExceptionMessage.ABORTING)
                close_app(-10);

            if (option_cloudserver == null)
                option_cloudserver = xbs_cloudlist.DEFAULT_CLOUDLIST_SERVER;

            if (option_cloudname != null)
            {
                if (option_password == null)
                    option_password = "";
                if (option_cloudname.Length >= xbs_cloudlist.MIN_CLOUDNAME_LENGTH)
                {
                    try
                    {
                        cloudlist.JoinOrCreateCloud(option_cloudserver, option_cloudname, option_maxnodes.ToString(), option_password, node_list.local_node.ip_public, node_list.local_node.port_public, node_list.local_node.nickname, xbs_upnp.isPortReachable, xbs_settings.xbslink_version);
                    }
                    catch (Exception e)
                    {
                        xbs_messages.addInfoMessage("!! ERROR connecting to cloud " + option_cloudname, xbs_message_sender.GENERAL, xbs_message_type.ERROR);
                        xbs_messages.addInfoMessage(e.Message, xbs_message_sender.GENERAL, xbs_message_type.ERROR);
                    }
                }
                else
                {
                    xbs_messages.addInfoMessage("!! ERROR - cloudname is too short. " + xbs_cloudlist.MIN_CLOUDNAME_LENGTH + " chars minimum", xbs_message_sender.GENERAL, xbs_message_type.ERROR);
                    close_app(-12);
                }
            }

            main_engine_loop();
        }