void NewAdaptersLoop() { try { while (true) { Thread.Sleep(5000); if (!isNdisFilterDriverOpen) { OpenDriver(); } allAdapters = NetworkInterface.GetAllNetworkInterfaces(); TCP_AdapterList adList = new TCP_AdapterList(); Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList); for (int x = 0; x < currentAdapters.Count; x++) { for (int y = 0; y < adList.m_nAdapterCount; y++) { if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle) { string name = Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256); currentAdapters[x].UpdateNetworkInterface(name.Substring(0, name.IndexOf((char)0x00))); } } } for (int x = 0; x < adList.m_nAdapterCount; x++) { bool found = false; for (int y = 0; y < currentAdapters.Count; y++) { if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle) { found = true; } } if (!found) { WinpkFilter newAdapter = new WinpkFilter(hNdisapi, adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256)); if (newAdapter.GetAdapterInformation() != null && !string.IsNullOrEmpty(newAdapter.GetAdapterInformation().Name)) { //lock (newAdapters) //{ newAdapters.Add(newAdapter); //} } } } } } catch (ThreadAbortException) { } catch (Exception e) { LogCenter.Instance.LogException(e); } }
void NewAdaptersLoop() { try { while (true) { Thread.Sleep(1000); if (!isNdisFilterDriverOpen) { OpenDriver(); } TCP_AdapterList adList = new TCP_AdapterList(); Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList); for (int x = 0; x < currentAdapters.Count; x++) { for (int y = 0; y < adList.m_nAdapterCount; y++) { if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle) { currentAdapters[x].UpdateNetworkInterface(Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256)); } } } for (int x = 0; x < adList.m_nAdapterCount; x++) { bool found = false; for (int y = 0; y < currentAdapters.Count; y++) { if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle) { found = true; } } if (!found) { WinpkFilter newAdapter = new WinpkFilter(hNdisapi, adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256)); if (newAdapter.GetAdapterInformation() != null && !string.IsNullOrEmpty(newAdapter.GetAdapterInformation().Name)) { lock (newAdapters) { newAdapters.Add(newAdapter); } } } } } } catch (ThreadAbortException tae) { } }
void NewAdaptersLoop() { try { while (true) { Thread.Sleep(5000); if (!isNdisFilterDriverOpen) { OpenDriver(); } allAdapters = NetworkInterface.GetAllNetworkInterfaces(); TCP_AdapterList adList = new TCP_AdapterList(); Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList); for (int x = 0; x < currentAdapters.Count; x++) { for (int y = 0; y < adList.m_nAdapterCount; y++) { if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle) { string name = Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256); currentAdapters[x].UpdateNetworkInterface(name.Substring(0, name.IndexOf((char)0x00))); } } } for (int x = 0; x < adList.m_nAdapterCount; x++) { bool found = false; for (int y = 0; y < currentAdapters.Count; y++) { if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle) found = true; } if (!found) { WinpkFilter newAdapter = new WinpkFilter(hNdisapi, adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256)); if (newAdapter.GetAdapterInformation() != null && !string.IsNullOrEmpty(newAdapter.GetAdapterInformation().Name)) { //lock (newAdapters) //{ newAdapters.Add(newAdapter); //} } } } } } catch (ThreadAbortException) { } catch (Exception e) { LogCenter.Instance.LogException(e); } }
void UpdateCurrentAdapters() { bool succeeded = false; while (!succeeded) { if (!isNdisFilterDriverOpen) OpenDriver(); TCP_AdapterList adList = new TCP_AdapterList(); Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList); List<WinpkFilter> tempList = new List<WinpkFilter>(); //Populate with current adapters List<WinpkFilter> notFound = new List<WinpkFilter>(); for (int x = 0; x < currentAdapters.Count; x++) { bool found = false; for (int y = 0; y < adList.m_nAdapterCount; y++) { if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle) { currentAdapters[x].UpdateNetworkInterface(Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256)); tempList.Add(currentAdapters[x]); found = true; } } if (!found) { notFound.Add(currentAdapters[x]); } } //Deal with no longer existant adapters for (int x = 0; x < notFound.Count; x++) { notFound[x].StopProcessing(); } //Adding any new adapters for (int x = 0; x < adList.m_nAdapterCount; x++) { bool found = false; for (int y = 0; y < currentAdapters.Count; y++) { if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle) found = true; } if (!found) { WinpkFilter newAdapter = new WinpkFilter(hNdisapi, adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256)); if (newAdapter.GetAdapterInformation() != null && !string.IsNullOrEmpty(newAdapter.GetAdapterInformation().Name)) { tempList.Add(newAdapter); } } } currentAdapters = new List<WinpkFilter>(tempList); succeeded = true; } }
void UpdateCurrentAdapters() { bool succeeded = false; while (!succeeded) { if (!isNdisFilterDriverOpen) { OpenDriver(); } TCP_AdapterList adList = new TCP_AdapterList(); Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList); List <WinpkFilter> tempList = new List <WinpkFilter>(); //Populate with current adapters List <WinpkFilter> notFound = new List <WinpkFilter>(); for (int x = 0; x < currentAdapters.Count; x++) { bool found = false; for (int y = 0; y < adList.m_nAdapterCount; y++) { if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle) { currentAdapters[x].UpdateNetworkInterface(Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256)); tempList.Add(currentAdapters[x]); found = true; } } if (!found) { notFound.Add(currentAdapters[x]); } } //Deal with no longer existant adapters for (int x = 0; x < notFound.Count; x++) { notFound[x].StopProcessing(); } //Adding any new adapters for (int x = 0; x < adList.m_nAdapterCount; x++) { bool found = false; for (int y = 0; y < currentAdapters.Count; y++) { if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle) { found = true; } } if (!found) { WinpkFilter newAdapter = new WinpkFilter(hNdisapi, adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256)); if (newAdapter.GetAdapterInformation() != null && !string.IsNullOrEmpty(newAdapter.GetAdapterInformation().Name)) { tempList.Add(newAdapter); } } } currentAdapters = new List <WinpkFilter>(tempList); succeeded = true; } }
void NewAdaptersLoop() { try { while (true) { Thread.Sleep(1000); if (!isNdisFilterDriverOpen) { OpenDriver(); } TCP_AdapterList adList = new TCP_AdapterList(); Ndisapi.GetTcpipBoundAdaptersInfo(hNdisapi, ref adList); for (int x = 0; x < currentAdapters.Count; x++) { for (int y = 0; y < adList.m_nAdapterCount; y++) { if (adList.m_nAdapterHandle[y] == currentAdapters[x].adapterHandle) { currentAdapters[x].UpdateNetworkInterface(Encoding.ASCII.GetString(adList.m_szAdapterNameList, y * 256, 256)); } } } for (int x = 0; x < adList.m_nAdapterCount; x++) { bool found = false; for (int y = 0; y < currentAdapters.Count; y++) { if (adList.m_nAdapterHandle[x] == currentAdapters[y].adapterHandle) found = true; } if (!found) { WinpkFilter newAdapter = new WinpkFilter(hNdisapi, adList.m_nAdapterHandle[x], Encoding.ASCII.GetString(adList.m_szAdapterNameList, x * 256, 256)); if (newAdapter.GetAdapterInformation() != null && !string.IsNullOrEmpty(newAdapter.GetAdapterInformation().Name)) { lock (newAdapters) { newAdapters.Add(newAdapter); } } } } } } catch (ThreadAbortException tae) { } }