linux:如何在没有root权限的情况下获得无线ssid?
有没有办法在没有root权限的情况下获得当前的无线SSID?
iwconfig告诉我ESSID,但前提是我以root身份运行它. 解决方法
如果你看一下iwconfig(
wireless_tools)的源代码,你会看到这一行:
iwconfig.c:639: if(iw_get_ext(skfd,ifname,SIOCGIWESSID,&wrq) < 0) 该行负责获取ESSID(wireless.h).我认为只有root才有权限(开箱即用)来执行此操作,因此调用ioctl的函数iw_get_ext(在wireless_tools包的iwlib.h中定义)将返回EPERM(不允许操作). /*------------------------------------------------------------------*/ /* * Wrapper to extract some Wireless Parameter out of the driver */ static inline int iw_get_ext(int skfd,/* Socket to the kernel */ const char * ifname,/* Device name */ int request,/* WE ID */ struct iwreq * pwrq) /* Fixed part of the request */ { /* Set device name */ strncpy(pwrq->ifr_name,IFNAMSIZ); /* Do the request */ return(ioctl(skfd,request,pwrq)); } 你有2个解决方案: >使用setuid允许用户使用iwconfig命令: sudo chmod u s / sbin / iwconfig http://packetlife.net/blog/2010/mar/19/sniffing-wireshark-non-root-user/ http://peternixon.net/news/2012/01/28/configure-tcpdump-work-non-root-user-opensuse-using-file-system-capabilities/ http://www.lids.org/lids-howto/node48.html http://lwn.net/Articles/430462/ 最后,您可以使用strace跟踪所有系统调用并确认ioctl调用是否对此负责: 以root身份执行此操作: #strace /sbin/iwconfig your_interface_name > strace_iwconfig_root.log 和普通用户一样: $strace /sbin/iwconfig your_interface_name > strace_iwconfig_normal.log 并比较结果. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |