Exemplo n.º 1
0
 public void updateConnections()
 {
     lock (connectionsLock)
     {
         _Connections = new List <IcsConnection>();
         try
         {
             foreach (INetConnection conn in this._NSManager.EnumEveryConnection)
             {
                 IcsConnection c = new IcsConnection(this._NSManager, conn);
                 try{
                     if (c.DeviceName != null)
                     {
                         _Connections.Add(c);
                     }
                 }catch {
                 }
             }
             ;
         }
         catch
         {
             Trace.TraceInformation("ICS: Unable to get list of connections");
         }
     }
 }
Exemplo n.º 2
0
 public IcsManager()
 {
     this.Init();
     privateIP = "";
     privateStrGUID = "";
     connectionsLock = "";
     publicConn = null;
     updateConnections();
 }
Exemplo n.º 3
0
 public IcsManager()
 {
     this.Init();
     privateIP       = "";
     privateStrGUID  = "";
     connectionsLock = "";
     publicConn      = null;
     updateConnections();
 }
Exemplo n.º 4
0
 public void setPublicConnection(string guid)
 {
     publicStrGuid = guid;
     publicConn    = null;
     if (publicStrGuid.Equals(autoPublicConnection))
     {
         return;
     }
     lock (connectionsLock)
     {
         publicConn = (from c in Connections
                       where c.IsMatch(guid)
                       select c).FirstOrDefault();
     }
 }
Exemplo n.º 5
0
 public bool IsPublicConnected()
 {
     if ((publicConn != null) && publicConn.IsConnected)
     {
         return(true);
     }
     if (publicStrGuid.Equals(autoPublicConnection))
     {
         NetworkInterface nicInet = null;
         foreach (var nic in NetworkInterface.GetAllNetworkInterfaces())
         {
             IPv4InterfaceProperties ip4Props = nic.GetIPProperties().GetIPv4Properties();
             if ((nic.GetIPProperties().GatewayAddresses.Count > 0) && (ip4Props != null) && (nic.OperationalStatus == OperationalStatus.Up))
             {
                 if (nicInet == null)
                 {
                     nicInet = nic;
                 }
                 else
                 if (ip4Props.Index < nicInet.GetIPProperties().GetIPv4Properties().Index)
                 {
                     nicInet = nic;
                 }
             }
         }
         if (nicInet != null)
         {
             lock (connectionsLock)
             {
                 publicConn = (from c in Connections
                               where !c.IsMatch(privateStrGUID) &&
                               c.IsMatch(nicInet.Id)
                               select c).FirstOrDefault();
                 if (publicConn != null)
                 {
                     Trace.TraceInformation("ICS: Detected internet connection {0}", nicInet.Name);
                 }
             }
         }
         else
         {
             Trace.TraceInformation("ICS: Unable to lookup internet connection");
         }
     }
     return((publicConn != null) && publicConn.IsConnected);
 }
Exemplo n.º 6
0
        public void EnableIcs(Guid publicGuid, Guid privateGuid)
        {
            if (!this.SharingInstalled)
            {
                throw new Exception("Internet Connection Sharing NOT Installed");
            }

            var connections = this.Connections;

            IcsConnection publicConn = (from c in connections
                                        where c.IsMatch(publicGuid)
                                        select c).First();

            IcsConnection privateConn = (from c in connections
                                         where c.IsMatch(privateGuid)
                                         select c).First();

            this.DisableIcsOnAll();

            publicConn.EnableAsPublic();
            privateConn.EnableAsPrivate();
        }
Exemplo n.º 7
0
 public void updateConnections()
 {
     lock (connectionsLock)
     {
         _Connections = new List<IcsConnection>();
         try
         {
             foreach (INetConnection conn in this._NSManager.EnumEveryConnection)
             {
                 IcsConnection c = new IcsConnection(this._NSManager, conn);
                 try{
                     if(c.DeviceName!=null)
                       _Connections.Add(c);
                 }catch{
                 }
             };
         }
         catch
         {
             Trace.TraceInformation("ICS: Unable to get list of connections");
         }
     }
 }
Exemplo n.º 8
0
 public void setPublicConnection(string guid)
 {
     publicStrGuid = guid;
     publicConn = null;
     if (publicStrGuid.Equals(autoPublicConnection))return;
     lock (connectionsLock)
     {
         publicConn = (from c in Connections
                           where c.IsMatch(guid)
                           select c).FirstOrDefault();
     }
 }
Exemplo n.º 9
0
 public bool IsPublicConnected()
 {
     if ((publicConn != null) && publicConn.IsConnected) return true;
     if (publicStrGuid.Equals(autoPublicConnection))
     {
         NetworkInterface nicInet = null;
         foreach (var nic in NetworkInterface.GetAllNetworkInterfaces()) {
             IPv4InterfaceProperties ip4Props = nic.GetIPProperties().GetIPv4Properties();
             if ((nic.GetIPProperties().GatewayAddresses.Count>0)&&(ip4Props!=null) && (nic.OperationalStatus == OperationalStatus.Up)) {
                 if (nicInet == null) nicInet = nic;
                 else
                     if (ip4Props.Index < nicInet.GetIPProperties().GetIPv4Properties().Index)
                         nicInet = nic;
             }
         }
         if (nicInet != null)
             lock (connectionsLock)
             {
                 publicConn = (from c in Connections
                                   where !c.IsMatch(privateStrGUID) &&
                                     c.IsMatch(nicInet.Id)
                                   select c).FirstOrDefault();
                 if(publicConn!=null)
                     Trace.TraceInformation("ICS: Detected internet connection {0}", nicInet.Name);
             }
         else
         {
             Trace.TraceInformation("ICS: Unable to lookup internet connection");
         }
     }
     return ((publicConn != null) && publicConn.IsConnected);
 }
Exemplo n.º 10
0
 public SharableConnection(IcsConnection conn)
 {
     this.Name = conn.Name;
     this.DeviceName = conn.DeviceName;
     this.Guid = conn.Guid;
 }