Ejemplo n.º 1
0
        public void GetConnectionStatus()
        {
            try
            {
                MbnInterfaceManager  mbnInfMgr          = new MbnInterfaceManager();
                IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
                if (mbnInfMgrInterface == null)
                {
                    string connectionMessage = "no connection found!";
                }

                if (mbnInfMgrInterface != null)
                {
                    IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
                    if (mobileInterfaces != null && mobileInterfaces.Length > 0)
                    {
                        // Use the first interface, as there should only be one mobile data adapter
                        IMbnSignal signalDetails = mobileInterfaces[1] as IMbnSignal;

                        Int32.TryParse(signalDetails.GetSignalStrength().ToString(), out PhoneSignal);
                        PhoneSignal = Convert.ToInt32(((float)PhoneSignal / 16) * 100);

                        MBN_PROVIDER provider = mobileInterfaces[0].GetHomeProvider();
                        PhoneNetwork = provider.providerName.ToString();

                        if (String.IsNullOrEmpty(SIMNumber))
                        {
                            try
                            {
                                IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();

                                if (subInfo != null)
                                {
                                    SIMNumber = (subInfo.SimIccID);
                                }
                                else
                                {
                                    Console.WriteLine("Unable to read SIM info");
                                }
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Unable to read SIM info");
                            }
                        }
                        else
                        {
                        }
                    }
                }
                Console.WriteLine("no good connection");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 2
0
        public string GetMobileNumber()
        {
            IMbnInterfaceManager      interfaceManager = null;
            IMbnInterface             inf        = null;
            IMbnSubscriberInformation subscriber = null;

            try
            {
                interfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager();
                inf        = interfaceManager.GetInterface(InterfaceID);
                subscriber = inf.GetSubscriberInformation();

                foreach (var ob in subscriber.TelephoneNumbers)
                {
                    if (ob != null)
                    {
                        return((string)ob);
                    }
                }
            }
            catch (Exception e)
            {
                logger.Warn(e);
            }
            finally
            {
                if (subscriber != null)
                {
                    Marshal.FinalReleaseComObject(subscriber);
                }
                if (inf != null)
                {
                    Marshal.FinalReleaseComObject(inf);
                }
                if (interfaceManager != null)
                {
                    Marshal.FinalReleaseComObject(interfaceManager);
                }
            }

            return("Unknown");
        }
Ejemplo n.º 3
0
        public void Test()
        {
            IMbnInterfaceManager      interfaceManager = null;
            IMbnInterface             inf        = null;
            IMbnSubscriberInformation subscriber = null;

            try
            {
                interfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager();
                inf        = interfaceManager.GetInterface(InterfaceID);
                subscriber = inf.GetSubscriberInformation();

                uint outCode = 0;
                inf.ScanNetwork(out outCode);

                uint age   = 0;
                var  array = inf.GetVisibleProviders(out age);

                var provider = inf.GetHomeProvider();

                //inf.SetPreferredProviders(new MBN_PROVIDER[] { plusProvider }, out outCode);

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(mobileProfileTemplate);

                xml["MBNProfile"]["SubscriberID"].InnerText = subscriber.SubscriberID;
                xml["MBNProfile"]["SimIccID"].InnerText     = subscriber.SimIccID;

                //Console.WriteLine("Profile: " + xml.OuterXml);

                IMbnConnection conn = null;

                try
                {
                    conn = inf.GetConnection();

                    //MBN_ACTIVATION_STATE state;
                    //string profile;
                    //conn.GetConnectionState(out state, out profile);

                    uint requestId;
                }
                finally
                {
                    if (conn != null)
                    {
                        Marshal.FinalReleaseComObject(conn);
                    }
                }
            }
            finally
            {
                if (subscriber != null)
                {
                    Marshal.FinalReleaseComObject(subscriber);
                }
                if (inf != null)
                {
                    Marshal.FinalReleaseComObject(inf);
                }
                if (interfaceManager != null)
                {
                    Marshal.FinalReleaseComObject(interfaceManager);
                }
            }
        }
Ejemplo n.º 4
0
        void ExecuteAction(ActionType action)
        {
            IMbnInterfaceManager      interfaceManager = null;
            IMbnInterface             inf        = null;
            IMbnSubscriberInformation subscriber = null;

            try
            {
                interfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager();
                inf        = interfaceManager.GetInterface(InterfaceID);
                subscriber = inf.GetSubscriberInformation();

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(mobileProfileTemplate);

                xml["MBNProfile"]["SubscriberID"].InnerText = subscriber.SubscriberID;
                xml["MBNProfile"]["SimIccID"].InnerText     = subscriber.SimIccID;

                //Console.WriteLine("Profile: " + xml.OuterXml);

                IMbnConnection conn = null;

                try
                {
                    conn = inf.GetConnection();

                    //MBN_ACTIVATION_STATE state;
                    //string profile;
                    //conn.GetConnectionState(out state, out profile);

                    uint requestId;

                    if (action == ActionType.Connect)
                    {
                        conn.Connect(MBN_CONNECTION_MODE.MBN_CONNECTION_MODE_TMP_PROFILE, xml.OuterXml, out requestId);
                    }
                    else
                    {
                        conn.Disconnect(out requestId);
                    }
                }
                finally
                {
                    if (conn != null)
                    {
                        Marshal.FinalReleaseComObject(conn);
                    }
                }
            }
            finally
            {
                if (subscriber != null)
                {
                    Marshal.FinalReleaseComObject(subscriber);
                }
                if (inf != null)
                {
                    Marshal.FinalReleaseComObject(inf);
                }
                if (interfaceManager != null)
                {
                    Marshal.FinalReleaseComObject(interfaceManager);
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var process = new Process
            {
                StartInfo =
                {
                    FileName               = "netsh.exe",
                    Arguments              = "wlan show interfaces ",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            process.Start();
            var output = process.StandardOutput.ReadToEnd();

            var MProcess = new Process
            {
                StartInfo =
                {
                    FileName               = "netsh.exe",
                    Arguments              = "mbn show interface",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            MProcess.Start();
            var MOutput = MProcess.StandardOutput.ReadToEnd();

            var profileProcess = new Process
            {
                StartInfo =
                {
                    FileName               = "netsh.exe",
                    Arguments              = "mbn show interface BarningMobiel",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            profileProcess.Start();
            var profileOutput = profileProcess.StandardOutput.ReadToEnd();

            var wlanEnabled   = output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.Contains("There is no wireless interface on the system."));
            var wlanState     = output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.Contains("State"));
            var mobileState   = MOutput.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.Contains("State"));
            var mobileEnabled = MOutput.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.Contains("There is no Mobile Broadband interface"));
            var mobilePaused  = MOutput.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.Contains("Provider Name"));

            //get the simcard information
            try
            {
                MbnInterfaceManager  mbnInfMgr          = new MbnInterfaceManager();
                IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
                if (mbnInfMgrInterface != null)
                {
                    IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
                    if (mobileInterfaces != null && mobileInterfaces.Length > 0)
                    {
                        // Just use the first interface
                        IMbnSubscriberInformation subInfo = mobileInterfaces[0].GetSubscriberInformation();

                        Console.WriteLine(subInfo);

                        if (subInfo != null)
                        {
                            SIMNumber = subInfo.SimIccID;

                            Console.WriteLine(SIMNumber);
                            // Get the connection profile
                            MbnConnectionProfileManager  mbnConnProfileMgr          = new MbnConnectionProfileManager();
                            IMbnConnectionProfileManager mbnConnProfileMgrInterface = mbnConnProfileMgr as IMbnConnectionProfileManager;
                            if (mbnConnProfileMgrInterface != null)
                            {
                                bool   connProfileFound = false;
                                string profileName      = String.Empty;
                                Console.WriteLine(profileOutput);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Console.WriteLine(e);
            }

            //check if there is a mobile device
            if (!MOutput.Contains("Mobile Broadband Service (wwansvc) is not running."))
            {
                //if there is a mobile interface enabled
                if (!MOutput.Contains("There is no Mobile Broadband interface"))
                {
                    //check connection status
                    if (mobileState != null)
                    {
                        //check if sim is already known bij the system
                        //compare the device id from the system with the simsccid(emei) of the profile

                        //get the value from the string
                        string deviceIdstring = Regex.Match(SIMNumber, @"\d+").Value;
                        //convert to decimal becouse the value is more than the int.max number(9digits)
                        decimal deviceIdInt = 0;
                        //parse
                        deviceIdInt = Decimal.Parse(deviceIdstring);
                        //do the same with the xml number
                        decimal xml_subscriberIdInt = 0;
                        xml_subscriberIdInt = decimal.Parse(xml_subscriberId());
                        //if there is a match the continue else create the profile
                        if (deviceIdInt != xml_subscriberIdInt)
                        {
                            ColorTextAlert("simiccid number from mbnapi =" + deviceIdInt + "simicc number from profile =" + xml_subscriberIdInt + " are not the same");
                            createMobileProfile();
                        }
                        else
                        {
                            // ColorTextAlert("deviceid number from netsh =" + deviceIdInt + "Imei number from profile =" + xml_subscriberIdInt + "are the same");
                            //dont change the words
                            if (mobileState.Contains("Not connected"))
                            {
                                ColorTextAlert("Connecting to mobile.......");
                                connectToMobiel(false);
                            }
                            else if (mobileState.Contains("connected"))
                            {
                                ColorText("Connected to mobiel ,you`re welcome. ;-)");
                            }
                        }
                    }
                }
                else if (MOutput.Contains("There is no Mobile Broadband interface"))
                {
                    ColorTextAlert("enable mobiel interface...");
                    enableMobiel();
                }
            }



            //check if there is a wifi connection interface
            if (output.Contains("There is no wireless interface on the system"))
            {
                enableWiFi();
            }
            else
            {
                try
                {
                    //dont change the words
                    if (wlanState.Contains("disconnected"))
                    {
                        ColorTextAlert("connecting to Wi-Fi......");
                        connectToWifi(false);
                    }
                    else if (wlanState.Contains("connected"))
                    {
                        ColorText("Connected to Wifi ,you re welcome. ;-)");
                    }
                }
                catch (NullReferenceException e)
                {
                    ColorTextAlert("No Wlan interface found on the system" + e);
                }
            }

            filesystemwatcher_keepconnected();
            Console.Read();
        }