NetworkInfo.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "NetConfig.h"
  3. class NetCardInfo {
  4. public:
  5. NetCardInfo();
  6. struct Info {
  7. std::string adapter_name; // 适配器的GUID
  8. std::string friendly_name; // 适配器的名字
  9. std::string physical_addr; // mac地址
  10. std::string ip; // ip
  11. std::string ip_mask; // 子网掩码
  12. std::string gateway; // 网关
  13. std::string default_dns; // 默认dns
  14. std::string backup_dns; // 备选dns
  15. };
  16. static std::vector<std::shared_ptr<NetCardInfo>> GetNetworkInfo();
  17. const Info& GetNetCardInfo();
  18. void show();
  19. void show(char *buffer, int len);
  20. bool SetDns(const std::string& default_dns, const std::string& backup_dns);
  21. bool SetAutoDns(); // To clear the gateway,call this function.
  22. bool SetIpConfig(const std::string& ip, const std::string& ip_mask);
  23. // To clear the gateway,set your gateway to the same IP you use.
  24. bool SetGateway(const std::string& gateway);
  25. int get_last_error_code() {
  26. return config_->get_last_error_code();
  27. }
  28. protected:
  29. bool ParseInfo(PIP_ADAPTER_INFO adapter_info);
  30. bool ParseInfo(PIP_ADAPTER_ADDRESSES adapter_addresses);
  31. private:
  32. Info info_; // 网卡信息
  33. std::shared_ptr<NetConfig> config_;
  34. };