我可以在Linux中从C代码获取SSID和MAC地址吗?

标签 c networking ssid

我正在为我的 Majaro Linux 编写一个 C 备份程序。仅当我连接到家庭网络时,它才必须在特定时间在我的家庭本地服务器中备份文件。所以我需要获取当前网络的SSIDMAC地址来确定它是否是我的网络。

是否有 Linux(Arch) 默认命令、C 库函数或文件包含此信息?

我已经尝试过一些 Linux 工具,例如 ifconfig,但它对我来说毫无用处。

救命!

最佳答案

完成

感谢大家的帮助,特别是Iliya Iliev对此 library 。 它运行完美。

这正是我一直在寻找的东西!

我只是将它添加到我的主项目中。

#include "../wifi_scan.h"
#include <stdio.h>  
#include <unistd.h> 

const char *bssid_to_string(const uint8_t bssid[BSSID_LENGTH], char  bssid_string[BSSID_STRING_LENGTH])
    {
        snprintf(bssid_string, BSSID_STRING_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
             bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
        printf("%x\n", bssid[5]);
        return bssid_string;
    }

    int main(int argc, char **argv){

        struct wifi_scan *wifi=NULL;
        struct station_info station;
        char mac[BSSID_STRING_LENGTH]; 

        wifi=wifi_scan_init(argv[1]);
        wifi_scan_station(wifi, &station);

        printf("ssid = %s mac = %s \n", station.ssid, bssid_to_string(station.bssid, mac));

        wifi_scan_close(wifi);

    }

关于我可以在Linux中从C代码获取SSID和MAC地址吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56619504/

相关文章:

ios - 从网络获取 SSID 的简单代码

python - 如何轻松地将 CLI 输出转换为字符串

c - 为什么我在 C 中得到这么大的数字?

c - 二进制搜索算法的平均性能?

c++ - 客户端连接到服务器,但服务器认为客户端没有连接到 C++

iphone - 单个请求到多个异步响应

algorithm - Dijkstra算法计算N条最短路径

python - 错误: value of type 'PyObject' (aka '_object' ) is not contextually convertible to 'bool'

c - 虚拟地址 : multiple of four aligned - writing to address "in between"

ios7 - 获取 iOS 7 范围内的 SSID