采集信号强度RSSI及其SSID的程序的程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

我现在正在做基于信号强度的无线定位,利用无线网卡接受3个AP的信号强度从而实现定位,现在编写的采集信号强度RSSI及其SSID的程序写好了,能够准确的采集到数据。但是如何实现用一个无线网卡同时采集3个AP的相关值(RSSI及其SSID)呢?请达人指点!谢谢!采集信号强度RSSI及其SSID的程序的程序如下://***************************************************************************//thisprogramisaboutSSIDandRSSIofwirelesslocalareaofnetwork//therearethreesteps://1.getthedevicenameAPI:GetAdaptersInfo()//2.getthehandleofthedeviceAPI:CreateFile()//3.controlthedeviceandqurrytheOIDAPI:DeviceIoControl()//***************************************************************************#includewindows.h#includewinioctl.h#includestring.h#includestdio.h#includeIPHlpApi.h#includeIPTypes.h#includeOID80211.h#includeHelp.h#pragmacomment(lib,Iphlpapi.lib)#pragmacomment(lib,Advapi32.lib)//openprocesstokenCHAR*GetNicName();//getdevicenameHANDLEOpenHandle(CHAR*pNicName);//getthehandleBOOLGetSSID(HANDLEHNIC,DWORDOIDSSID,NDIS_802_11_SSID*SSID);//querythessidBOOLGetRSSI(HANDLEHNIC,DWORDOIDRSSI,NDIS_802_11_RSSI*RSSI);//querytherssiintmain(){CHAR*pNicName;//pNicNameisNICnameHANDLEHNIC;DWORDOIDSSID=OID_802_11_SSID;//OIDtobequeriedDWORDOIDRSSI=OID_802_11_RSSI;NDIS_802_11_SSIDSSID;NDIS_802_11_RSSIRSSI;pNicName=GetNicName();//getthedevicenameofNICHNIC=OpenHandle(pNicName);//getthehandleofdeviceif(HNIC==INVALID_HANDLE_VALUE)//wecan'tgettheNIChandle{PRINTF((FailedtogettheNIChandle!\n));return0;}if(GetSSID(HNIC,OIDSSID,&SSID))//querythessid{SSID.Ssid[SSID.SsidLength]='\0';PRINTF((SSID=%s\n,SSID.Ssid));}if(GetRSSI(HNIC,OIDRSSI,&RSSI))//querytherssi{PRINTF((RSSI=%ddbm\n,RSSI));}CloseHandle(HNIC);return1;}CHAR*GetNicName(){CHARNicName[300];//theNICnameCHAR*preName=\\\\.\\;//theprestringofnameCHAR*pNicName=NULL;//returnparameterDWORDDResult;//flagofGetAdaptersInfo()//parametersofGetAdaptersInfo()PIP_ADAPTER_INFOpAdapter;//buffertoreceivedataIP_ADAPTER_INFONicInfo;//structureofbuffertoreceivedataULONGOutBufLen;//sizeofdatareturnedOutBufLen=sizeof(NicInfo);DResult=GetAdaptersInfo(&NicInfo,&OutBufLen);if(DResult==ERROR_BUFFER_OVERFLOW){GetAdaptersInfo(&NicInfo,&OutBufLen);}elseif(DResult!=ERROR_SUCCESS){PRINTF((GetNicNameError:%d\n,GetLastError()));returnNULL;}pAdapter=&NicInfo;if(pAdapter!=NULL){pNicName=strcpy(NicName,preName);pNicName=strcat(NicName,pAdapter-AdapterName);}returnpNicName;}HANDLEOpenHandle(CHAR*pNicName){HANDLEHNIC;//handleofnetworkinterfacecard//parameterbetweenCreateFile()andDeviceIoControl()//parametersofCreateFile()DWORDDesiredAccess;//accessmodeDWORDShareMode;//sharemodeLPSECURITY_ATTRIBUTESlpSecurityAttributes;//SDDWORDCreationDistribution;//howtocreateDWORDFlagsAndAttributes;//fileattributesHANDLETemplateFile;//handletotemplatefile//evaluateparametersofHandleCreateFile()DesiredAccess=GENERIC_READ|GENERIC_WRITE;ShareMode=0;lpSecurityAttributes=NULL;CreationDistribution=OPEN_EXISTING;FlagsAndAttributes=FILE_ATTRIBUTE_NORMAL;TemplateFile=NULL;HNIC=CreateFile(pNicName,DesiredAccess,ShareMode,lpSecurityAttributes,CreationDistribution,FlagsAndAttributes,TemplateFile);returnHNIC;}BOOLGetSSID(HANDLEHNIC,DWORDOIDSSID,NDIS_802_11_SSID*SSID){BOOLBResult;//flagofresultDWORDjunk;//discardresults//parametersofDeviceIoControl()DWORDdwIoControlCode;//operationLPVOIDlpInBuffer;//inputdatabufferDWORDnInBufferSize;//sizeofinputdatabufferLPVOIDlpOutBuffer;//outputdatabufferDWORDnOutBufferSize;//sizeofoutputdatabufferLPDWORDlpBytesReturned;//bytecountLPOVERLAPPEDlpOverlapped;//overlappedinformation//evaluateparametersofBOOLDeviceIoControl()dwIoControlCode=IOCTL_NDIS_QUERY_GLOBAL_STATS;lpInBuffer=&OIDSSID;nInBufferSize=4;lpOutBuffer=SSID;nOutBufferSize=sizeof(*SSID);lpBytesReturned=&junk;lpOverlapped=NULL;BResult=DeviceIoControl(HNIC,dwIoControlCode,lpInBuffer,nInBufferSize,lpOutBuffer,nOutBufferSize,lpBytesReturned,lpOverlapped);if(!BResult)//IOCTLfailed{DEBUGP((GetSSIDFailed,error%x\n,GetLastError()));return(FALSE);}return(BResult);}BOOLGetRSSI(HANDLEHNIC,DWORDOIDRSSI,NDIS_802_11_RSSI*RSSI){BOOLBResult;//flagofresultDWORDjunk;//discardresults//parametersofDeviceIoControl()DWORDdwIoControlCode;//operationLPVOIDlpInBuffer;//inputdatabufferDWORDnInBufferSize;//sizeofinputdatabufferLPVOIDlpOutBuffer;//outputdatabufferDWORDnOutBufferSize;//sizeofoutputdatabufferLPDWORDlpBytesReturned;//bytecountLPOVERLAPPEDlpOverlapped;//overlappedinformation//evaluateparametersofBOOLDeviceIoControl()dwIoControlCode=IOCTL_NDIS_QUERY_GLOBAL_STATS;lpInBuffer=&OIDRSSI;nInBufferSize=4;lpOutBuffer=RSSI;nOutBufferSize=sizeof(*RSSI);lpBytesReturned=&junk;//lpOverlapped=NULL;BResult=DeviceIoControl(HNIC,dwIoControlCode,lpInBuffer,nInBufferSize,lpOutBuffer,nOutBufferSize,lpBytesReturned,lpOverlapped);if(!BResult)//IOCTLfailed{DEBUGP((GetRSSIFailed,error%x\n,GetLastError()));return(FALSE);}return(BResult);}

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功