Exemplo n.º 1
0
vector<tstring> getWlanAdapterGuids()
{
	TRACE_ENTER();

	HANDLE hClient = NULL;
	WLAN_INTERFACE_INFO sInfo[64];
	RPC_TSTR strGuid = NULL;
	vector<tstring> nstrWlanAdapterGuids;

	if (!initWlanFunctions())
	{
		TRACE_PRINT("initWlanFunctions: error.");
		TRACE_EXIT();
		return nstrWlanAdapterGuids;
	}

	if (OpenHandleAndCheckVersion(&hClient) != ERROR_SUCCESS)
	{
		TRACE_PRINT("OpenHandleAndCheckVersion: error.");
		TRACE_EXIT();
		return nstrWlanAdapterGuids;
	}

	UINT nCount = EnumInterface(hClient, sInfo);
	for (UINT i = 0; i < nCount; ++i)
	{
		if (UuidToString(&sInfo[i].InterfaceGuid, &strGuid) == RPC_S_OK)
		{
			TRACE_PRINT1("EnumInterface: executing, strGuid = %s.", (TCHAR*) strGuid);
			nstrWlanAdapterGuids.push_back((TCHAR*) strGuid);
			RpcStringFree(&strGuid);
		}
	}

	TRACE_EXIT();
	return nstrWlanAdapterGuids;
}
Exemplo n.º 2
0
int TestWlanApi(int argc, _TCHAR* argv[])
{
	// init_lib( &cs );
	// return 0;
	HANDLE hClient = NULL;
	WLAN_INTERFACE_INFO sInfo[64];
	RPC_CSTR strGuid = NULL;

	TCHAR szBuffer[256];
	DWORD dwRead;
	if( OpenHandleAndCheckVersion( &hClient ) != ERROR_SUCCESS )
		return -1;

	UINT nCount = EnumInterface( hClient, sInfo );
	for( UINT i = 0; i < nCount; ++i )
	{
		if (UuidToStringA( &sInfo[i].InterfaceGuid, &strGuid) == RPC_S_OK)
		{
			printf( ("%d. %s\n\tDescription: %S\n\tState: %S\n"), 
				i, 
				strGuid, 
				sInfo[i].strInterfaceDescription, 
				GetInterfaceStateString(sInfo[i].isState) );

			RpcStringFreeA(&strGuid);
		}
	}

	UINT nChoice = 0;
	printf( "for choice wireless card:" );

	if( ReadConsole( GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL ) == FALSE )
	{
		puts( "error input" );
		return -1;
	}
	szBuffer[dwRead] = 0;
	nChoice = _ttoi( szBuffer );

	if( nChoice > nCount )
	{
		puts( "error input." );
		return -1;
	}

	ULONG ulOperatorCode = DOT11_OPERATION_MODE_NETWORK_MONITOR;
	if( ERROR_SUCCESS != WlanSetInterface( 
		hClient, 
		&sInfo[nChoice].InterfaceGuid, 
		wlan_intf_opcode_current_operation_mode,
		sizeof(ULONG),
		&ulOperatorCode,
		NULL ) )
	{
		puts( "enter monitor mode failed!" );
		return -1;
	}

	BOOL bRet = ReadFile( hClient, szBuffer, sizeof(szBuffer), &dwRead, NULL );

	_getch();
	ulOperatorCode = DOT11_OPERATION_MODE_EXTENSIBLE_STATION;
	if( ERROR_SUCCESS != WlanSetInterface( 
		hClient, 
		&sInfo[nChoice].InterfaceGuid, 
		wlan_intf_opcode_current_operation_mode,
		sizeof(ULONG),
		&ulOperatorCode,
		NULL ) )
	{
		puts( "enter monitor mode failed!" );
		return -1;
	}

	WlanCloseHandle( hClient, NULL );
	return 0;
}
Exemplo n.º 3
0
int MainInteractive()
{
	HANDLE hClient = NULL;
	WLAN_INTERFACE_INFO sInfo[64];
	RPC_TSTR strGuid = NULL;

	TCHAR szBuffer[256];
	DWORD dwRead;
	if (OpenHandleAndCheckVersion(&hClient) != ERROR_SUCCESS)
	{
		_tsystem(_T("PAUSE"));
		return -1;
	}

	UINT nCount = EnumInterface(hClient, sInfo);
	for (UINT i = 0; i < nCount; ++i)
	{
		if (UuidToString(&sInfo[i].InterfaceGuid, &strGuid) == RPC_S_OK)
		{
			ULONG ulOperationMode = -1;
			PULONG pOperationMode;
			DWORD dwResult = GetInterface(wlan_intf_opcode_current_operation_mode, (PVOID*)&pOperationMode, &sInfo[i].InterfaceGuid);
			if (dwResult != ERROR_SUCCESS)
			{
				_tprintf(_T("GetInterface error, error code = %d\n"), dwResult);
				_tsystem(_T("PAUSE"));
			}
			else
			{
				ulOperationMode = *pOperationMode;
				WlanFreeMemory(pOperationMode);
			}

			_tprintf(_T("%d. %s\n\tName: %s\n\tDescription: %s\n\tState: %s\n\tOperation Mode: %s\n"),
				i,
				strGuid,
				getAdapterNameFromGuid((TCHAR*) strGuid).c_str(),
				sInfo[i].strInterfaceDescription,
				GetInterfaceStateString(sInfo[i].isState),
				GetInterfaceOperationModeString(ulOperationMode));

			RpcStringFree(&strGuid);
		}
	}

	UINT nChoice = 0;
	GUID ChoiceGUID;
	LPGUID pChoiceGUID = NULL;
	_tprintf(_T("Enter the choice (0, 1,..) of the wireless card you want to operate on:\n"));

	if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL) == FALSE)
	{
		_putts(_T("Error input."));
		_tsystem(_T("PAUSE"));
		return -1;
	}
	szBuffer[dwRead] = 0;

	// TCHAR *aaa = _T("42dfd47a-2764-43ac-b58e-3df569c447da");
	// dwRead = sizeof(aaa);

	TCHAR buf[256];
	_stprintf_s(buf, 256, _T("{%s}"), szBuffer);

	if (dwRead > 32)
	{
		if (myGUIDFromString(buf, &ChoiceGUID) != TRUE)
		{
			_tprintf(_T("UuidFromString error, error code = %d\n"), -1);
			_tsystem(_T("PAUSE"));
		}
		else
		{
			pChoiceGUID = &ChoiceGUID;
		}
	}
	else
	{
		nChoice = _ttoi(szBuffer);

		if (nChoice > nCount)
		{
			_putts(_T("No such index."));
			_tsystem(_T("PAUSE"));
			return -1;
		}

		pChoiceGUID = &sInfo[nChoice].InterfaceGuid;
	}

	UINT nSTate = 0;
	ULONG ulOperationMode = -1;
	_tprintf(_T("Enter the operation mode (0, 1 or 2) you want to switch to for the chosen wireless card:\n"));
	_tprintf(_T("0: Extensible Station (ExtSTA)\n1: Network Monitor (NetMon)\n2: Extensible Access Point (ExtAP)\n"));

	if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL) == FALSE)
	{
		_putts(_T("Error input."));
		_tsystem(_T("PAUSE"));
		return -1;
	}
	szBuffer[dwRead] = 0;
	nSTate = _ttoi(szBuffer);

	if (nSTate != 0 && nSTate != 1 && nSTate != 2)
	{
		_putts(_T("Only 0, 1 and 2 are valid inputs."));
		_tsystem(_T("PAUSE"));
		return -1;
	}
	if (nSTate == 0)
	{
		ulOperationMode = DOT11_OPERATION_MODE_EXTENSIBLE_STATION;
	}
	else if (nSTate == 1)
	{
		ulOperationMode = DOT11_OPERATION_MODE_NETWORK_MONITOR;
	}
	else // nSTate == 2
	{
		ulOperationMode = DOT11_OPERATION_MODE_EXTENSIBLE_AP;
	}

	DWORD dwResult = SetInterface(wlan_intf_opcode_current_operation_mode, (PVOID*)&ulOperationMode, pChoiceGUID);
	if (dwResult != ERROR_SUCCESS)
	{
		_tprintf(_T("SetInterface error, error code = %d\n"), dwResult);
		_tsystem(_T("PAUSE"));
	}
	else
	{
		_tprintf(_T("SetInterface success!\n"));
	}

	return 0;
}
Exemplo n.º 4
0
void EnumObjects(IHTMLDocument2 *pIHTMLDocument2)
{
	if(!pIHTMLDocument2) return;

	HRESULT hr;
	USES_CONVERSION;

	CComPtr< IHTMLElementCollection > spAllCollection;
	hr = pIHTMLDocument2->get_all(&spAllCollection);	//取得document.all的集合
	if (FAILED(hr))
	{
		cout << _T("错误: 获取document.all集合IHTMLElementCollection!") << endl;
		return;
	}

	IDispatch *pDisp = NULL;
	hr = spAllCollection->tags(CComVariant(_T("OBJECT")), &pDisp);
	if (FAILED(hr))
	{
		cout << _T("错误: 获取document.all.tags('OBJECT')集合IHTMLElementCollection!") << endl;
		return;
	}

	CComQIPtr <IHTMLElementCollection> spObjectCollection = pDisp;
	long nObjectCount = 0;				//取得Embed个数
	hr = spObjectCollection->get_length(&nObjectCount);
	if (FAILED(hr))
	{
		cout << _T("错误: 获取Object集合IHTMLElementCollection的长度!") << endl;
	}

	cout << "Object对象共: " << nObjectCount << endl;

	CComBSTR bstrClassId, bstrData, bstrName, bstrCodeBase;
	CComBSTR bstrCodeType, bstrCode, bstrBaseHref, bstrType;

	CComQIPtr< IHTMLObjectElement > spObjectElement;

	for(long i = 0; i < nObjectCount; i++)
	{
		hr = spObjectCollection->item(CComVariant(i), CComVariant(), &pDisp);
		if (FAILED(hr)) continue;
		EnumInterface(pDisp, _T("OBJECT"));
		EnumConnectionPoint(pDisp, _T("OBJECT"));
		spObjectElement = pDisp;
		
		spObjectElement->get_classid(&bstrClassId);
		spObjectElement->get_data(&bstrData);
		spObjectElement->get_name(&bstrName);
		spObjectElement->get_codeBase(&bstrCodeBase);
		spObjectElement->get_codeType(&bstrCodeType);
		spObjectElement->get_code(&bstrCode);
		spObjectElement->get_BaseHref(&bstrBaseHref);
		spObjectElement->get_type(&bstrType);

		cout << i + 1 
			<< ": classid = " << (bstrClassId ? OLE2CT(bstrClassId) : _T(""))
			<< ", data = " << (bstrData ? OLE2CT(bstrData) : _T(""))
			<< ", name = " << (bstrName ? OLE2CT(bstrName) : _T(""))
			<< ", codeBase = " << (bstrCodeBase ? OLE2CT(bstrCodeBase) : _T(""))
			<< ", codeType = " << (bstrCodeType ? OLE2CT(bstrCodeType) : _T(""))
			<< ", code = " << (bstrCode ? OLE2CT(bstrCode) : _T(""))
			<< ", base href = " << (bstrBaseHref ? OLE2CT(bstrBaseHref) : _T(""))
			<< ", type = " << (bstrType ? OLE2CT(bstrType) :_T("")) 
			<< endl;
	
		hr = spObjectElement->get_object(&pDisp);
		if (FAILED(hr) || !pDisp) continue;
		//ViewObject(pDisp);
		EnumInterface(pDisp, _T("FLASH"));
		EnumConnectionPoint(pDisp, _T("FLASH"));
	}
	if (pDisp) 
	{
		pDisp->Release();
		pDisp = NULL;
	}	
}