int _tmain(int argc, _TCHAR* argv[]) { SetConsoleTitle(_T("WlanHelper for Npcap ") _T(WINPCAP_VER_STRING) _T(" (http://npcap.org)")); vector<tstring> strArgs; for (int i = 0; i < argc; i++) { strArgs.push_back(argv[i]); } if (argc == 1) { _tprintf(STR_COMMAND_USAGE); return -1; } else if (argc == 2) { if (strArgs[1] ==_T("-h") || strArgs[1] == _T("--help")) { _tprintf(STR_COMMAND_USAGE); return -1; } else if (strArgs[1] == _T("-i")) { _tprintf(_T("WlanHelper [Interactive Mode]:\n****************************************************\n")); return MainInteractive(); } else { _tprintf(STR_INVALID_PARAMETER); return -1; } } else if (argc == 3) { if (strArgs[2] == _T("mode")) { tstring strMode; if (GetCurrentOperationMode(getGuidFromAdapterName_Wrapper(strArgs[1]), strMode)) { _tprintf(_T("%s\n"), strMode.c_str()); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("modes")) { tstring strModes; if (GetOperationModeCapability(getGuidFromAdapterName_Wrapper(strArgs[1]), strModes)) { _tprintf(_T("%s\n"), strModes.c_str()); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("modes-monitor")) { tstring strModes; if (IsMonitorModeSupported(getGuidFromAdapterName_Wrapper(strArgs[1]))) { _tprintf(_T("%d\n"), TRUE); return 0; } else { _tprintf(_T("%d\n"), FALSE); return 0; } } else if (strArgs[2] == _T("channel")) { ULONG ulChannel; if (GetCurrentChannel(getGuidFromAdapterName_Wrapper(strArgs[1]), ulChannel)) { _tprintf(_T("%u\n"), ulChannel); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("freq")) { ULONG ulFrequency; if (GetCurrentFrequency(getGuidFromAdapterName_Wrapper(strArgs[1]), ulFrequency)) { _tprintf(_T("%u\n"), ulFrequency); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("modus")) { vector<tstring> nstrPhyTypes; if (GetSupportedPhyTypes(getGuidFromAdapterName_Wrapper(strArgs[1]), nstrPhyTypes)) { _tprintf(_T("%s\n"), printArray(nstrPhyTypes).c_str()); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("modus2")) { vector<tstring> nstrPhyList; if (GetDesiredPhyList(getGuidFromAdapterName_Wrapper(strArgs[1]), nstrPhyList)) { _tprintf(_T("%s\n"), printArray(nstrPhyList).c_str()); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("modu")) { tstring ulPhyID; if (GetCurrentPhyID(getGuidFromAdapterName_Wrapper(strArgs[1]), ulPhyID)) { _tprintf(_T("%s\n"), ulPhyID.c_str()); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else { _tprintf(STR_INVALID_PARAMETER); return -1; } } else if (argc == 4) { if (strArgs[2] == _T("mode")) { if (SetWlanOperationMode(getGuidFromAdapterName_Wrapper(strArgs[1]), strArgs[3])) { _tprintf(_T("Success\n")); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("channel")) { int ulChannel = _ttoi(strArgs[3].c_str()); if (SetCurrentChannel(getGuidFromAdapterName_Wrapper(strArgs[1]), ulChannel)) { _tprintf(_T("Success\n")); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("freq")) { int ulFrequency = _ttoi(strArgs[3].c_str()); if (SetCurrentFrequency(getGuidFromAdapterName_Wrapper(strArgs[1]), ulFrequency)) { _tprintf(_T("Success\n")); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else if (strArgs[2] == _T("modu")) { if (SetCurrentPhyID(getGuidFromAdapterName_Wrapper(strArgs[1]), strArgs[3])) { _tprintf(_T("Success\n")); return 0; } else { _tprintf(_T("Failure\n")); return -1; } } else { _tprintf(STR_INVALID_PARAMETER); return -1; } } else { _tprintf(_T("Error: too many parameters.\n")); return -1; } return 0; }
BOOL SetWlan(void) { #if 1 DownInterface("wlan0"); if (g_ConfigParam.ucWlanOperationMode == 1) /* Disable suspend in Ad-hoc mode */ g_netIsSuspendAllowed = FALSE; if (g_ConfigParam.ucWlanOperationMode == (unsigned char)IW_MODE_ADHOC) { wsp_set_network_adhoc(g_ConfigParam.acWlanESSID, g_ConfigParam.acWlanKey, g_ConfigParam.ulWlanChannel); } else { wsp_set_network_managed(g_ConfigParam.acWlanESSID, g_ConfigParam.acWlanKey); } #else DownInterface("wlan0"); /* ÔOWLAN */ if (g_ConfigParam.ucWlanOperationMode == 1) /* Disable suspend in Ad-hoc mode */ g_netIsSuspendAllowed = FALSE; if (!SetWlanOperationMode(g_apcNetworkInterface[1], (int)g_ConfigParam.ucWlanOperationMode)) fprintf(stderr, "Can not set operation mode.\n"); if (!SetWlanChannel(g_apcNetworkInterface[1], (int)g_ConfigParam.ulWlanChannel)) fprintf(stderr, "Can not set wireless channel.\n"); if (!SetWlanRegion(g_apcNetworkInterface[1], 0x40)) fprintf(stderr, "Can not set the region for wlan\n"); if (!SetWlanMTU(g_apcNetworkInterface[1], 460)) fprintf(stderr, "Can not set MTU for wlan\n"); if (!wlanSetBitrate(g_apcNetworkInterface[1],-1)) fprintf(stderr, "Can not set wlan bitrate\n"); switch (g_ConfigParam.ucWepSet) { case WEP_SET_DISABLE: SetWlanWepKey(g_apcNetworkInterface[1], NULL, -1, -1, g_ConfigParam.ulWepAuthentication); break; case WEP_SET_K64: SetWlanWepKey(g_apcNetworkInterface[1], NULL, -1, -1, g_ConfigParam.ulWepAuthentication); //Disable WEP key SetWlanESSID(g_apcNetworkInterface[1], (const char *)g_ConfigParam.acWlanESSID); DownInterface("wlan0"); if (SetWlanWepKey(g_apcNetworkInterface[1], g_ConfigParam.acWep64, 5, -1, g_ConfigParam.ulWepAuthentication) //SET WEP key && SetWlanWepKey(g_apcNetworkInterface[1], NULL, 0, -1, g_ConfigParam.ulWepAuthentication)//enable WEP ) diag_printf("set wepset k64\n"); break; case WEP_SET_K128: SetWlanWepKey(g_apcNetworkInterface[1], NULL, -1, -1, g_ConfigParam.ulWepAuthentication); //Disable WEP key SetWlanESSID(g_apcNetworkInterface[1], (const char *)g_ConfigParam.acWlanESSID); DownInterface("wlan0"); if (SetWlanWepKey(g_apcNetworkInterface[1], g_ConfigParam.acWep128, 13, -1, g_ConfigParam.ulWepAuthentication)//SET WEP key && SetWlanWepKey(g_apcNetworkInterface[1], NULL, 0, -1, g_ConfigParam.ulWepAuthentication)//enable WEP ) diag_printf("set wepset k128\n"); break; case WEP_SET_ASC: SetWlanWepKey(g_apcNetworkInterface[1], NULL, -1, -1, g_ConfigParam.ulWepAuthentication); //Disable WEP key SetWlanESSID(g_apcNetworkInterface[1], (const char *)g_ConfigParam.acWlanESSID); DownInterface("wlan0"); if (SetWlanWepKey(g_apcNetworkInterface[1], g_ConfigParam.acWepAsc, strlen((char *)g_ConfigParam.acWepAsc), -1, g_ConfigParam.ulWepAuthentication)//SET WEP key ) diag_printf("set wep set ascii\n"); break; } if (!SetWlanESSID(g_apcNetworkInterface[1], (const char *)g_ConfigParam.acWlanESSID)) { fprintf(stderr, "Can not set wireless ESSID.\n"); return FALSE; } else return TRUE; #endif }