示例#1
0
        public void EnableIcs()
        {
            if (!this.SharingInstalled)
            {
                Trace.TraceInformation("ICS: Sharing NOT Installed");
                throw new Exception("Sharing NOT Installed");
            }

            if (privateStrGUID.Equals(publicStrGuid))
            {
                Trace.TraceInformation("ICS:public=shared={0}", privateStrGUID);
                throw new Exception("Unable to share connection over itself");
            }

            try
            {
                setIpRegistry(privateStrGUID, "0.0.0.0", "255.255.255.0");
                setDHCPScope("255.255.255.255");
                IcsConnection privateConn;

                try {
                    publicConn.EnableAsPublic();
                } catch {
                    fixAdapters("IsIcsPublic = TRUE");
                    publicConn.EnableAsPublic();
                }

                lock (connectionsLock)
                {
                    privateConn = (from c in Connections
                                   where c.IsMatch(privateStrGUID)
                                   select c).First();
                }
                Trace.TraceInformation("ICS: Sharing Enabling");

                try {
                    privateConn.EnableAsPrivate();
                } catch {
                    fixAdapters("IsIcsPrivate  = TRUE");
                    privateConn.EnableAsPrivate();
                }
            }
            catch (Exception e)
            {
                Trace.TraceInformation("ICS: Sharing failed to start {0}", e.Message);
            }
        }
示例#2
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();
        }