Beispiel #1
0
 public static void CloseLocalPort(int port)
 {
     DisconnectWrapper.ConnectionInfo[] tcpTable = DisconnectWrapper.getTcpTable();
     for (int i = 0; i < tcpTable.Length; i++)
     {
         if (port == DisconnectWrapper.ntohs(tcpTable[i].dwLocalPort))
         {
             tcpTable[i].dwState = 12;
             IntPtr ptrToNewObject = DisconnectWrapper.GetPtrToNewObject(tcpTable[i]);
             int    num            = DisconnectWrapper.SetTcpEntry(ptrToNewObject);
         }
     }
 }
Beispiel #2
0
 public static void CloseLocalIP(string IP)
 {
     DisconnectWrapper.ConnectionInfo[] tcpTable = DisconnectWrapper.getTcpTable();
     for (int i = 0; i < tcpTable.Length; i++)
     {
         if (tcpTable[i].dwLocalAddr == DisconnectWrapper.IPStringToInt(IP))
         {
             tcpTable[i].dwState = 12;
             IntPtr ptrToNewObject = DisconnectWrapper.GetPtrToNewObject(tcpTable[i]);
             int    num            = DisconnectWrapper.SetTcpEntry(ptrToNewObject);
         }
     }
 }
Beispiel #3
0
 public static void CloseConnection(string connectionstring)
 {
     try
     {
         string[] array = connectionstring.Split(new char[]
         {
             '-'
         });
         if (array.Length != 4)
         {
             throw new Exception("Invalid connectionstring - use the one provided by Connections.");
         }
         string[] array2 = array[0].Split(new char[]
         {
             ':'
         });
         string[] array3 = array[1].Split(new char[]
         {
             ':'
         });
         string[] array4 = array2[0].Split(new char[]
         {
             '.'
         });
         string[] array5 = array3[0].Split(new char[]
         {
             '.'
         });
         DisconnectWrapper.ConnectionInfo connectionInfo = default(DisconnectWrapper.ConnectionInfo);
         connectionInfo.dwState = 12;
         byte[] value = new byte[]
         {
             byte.Parse(array4[0]),
             byte.Parse(array4[1]),
             byte.Parse(array4[2]),
             byte.Parse(array4[3])
         };
         byte[] value2 = new byte[]
         {
             byte.Parse(array5[0]),
             byte.Parse(array5[1]),
             byte.Parse(array5[2]),
             byte.Parse(array5[3])
         };
         connectionInfo.dwLocalAddr  = BitConverter.ToInt32(value, 0);
         connectionInfo.dwRemoteAddr = BitConverter.ToInt32(value2, 0);
         connectionInfo.dwLocalPort  = DisconnectWrapper.htons(int.Parse(array2[1]));
         connectionInfo.dwRemotePort = DisconnectWrapper.htons(int.Parse(array3[1]));
         IntPtr ptrToNewObject = DisconnectWrapper.GetPtrToNewObject(connectionInfo);
         int    num            = DisconnectWrapper.SetTcpEntry(ptrToNewObject);
         if (num == -1)
         {
             throw new Exception("Unsuccessful");
         }
         if (num == 65)
         {
             throw new Exception("User has no sufficient privilege to execute this API successfully");
         }
         if (num == 87)
         {
             throw new Exception("Specified port is not in state to be closed down");
         }
         if (num != 0)
         {
             throw new Exception("Unknown error (" + num + ")");
         }
     }
     catch
     {
     }
 }