国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - C# - C#獲取路由器外網(wǎng)IP,MAC地址的實現(xiàn)代碼

C#獲取路由器外網(wǎng)IP,MAC地址的實現(xiàn)代碼

2021-12-10 14:38C#教程網(wǎng) C#

這篇文章主要介紹了C#獲取路由器外網(wǎng)IP,MAC地址的實現(xiàn)代碼,需要的朋友可以參考下

C#實現(xiàn)的獲取路由器MAC地址,路由器外網(wǎng)地址。對于要獲取路由器MAC地址,一定需要知道路由器web管理系統(tǒng)的用戶名和密碼。至于獲取路由器的外網(wǎng)IP地址,可以不需要知道路由器web管理系統(tǒng)的用戶名和密碼,但是需要有一個代理頁面獲取客戶端公網(wǎng)ip地址的,這樣C#請求此頁面即可獲取到路由器公網(wǎng)ip地址。如

//getip.ashx

測試路由為水星 MR804,水星 MR808,都可以成功重啟路由和獲取到路由器MAC和外網(wǎng)IP地址

源代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
public class Router
{
  Encoding gb2312 = Encoding.GetEncoding(936);//路由器的web管理系統(tǒng)默認(rèn)編碼為gb2312
  /// <summary>
  /// 使用HttpWebRequest對象發(fā)送請求
  /// </summary>
  /// <param name="url"></param>
  /// <param name="encoding">編碼</param>
  /// <param name="cache">憑證</param>
  /// <returns></returns>
  private static string SendRequest(string url, Encoding encoding,CredentialCache cache)
  {
   HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
   if (cache != null)
   {
    request.PreAuthenticate = true;
    request.Credentials = cache;
   }
   string html = null;
   try
   {
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader srd = new StreamReader(response.GetResponseStream(), encoding);
    html = srd.ReadToEnd();
    srd.Close();
    response.Close();
   }
   catch (Exception ex) { html = "FALSE" + ex.Message; }
   return html;
  }
  /// <summary>
  /// 獲取路由MAC和外網(wǎng)IP地址
  /// </summary>
  /// <param name="RouterIP">路由IP地址,就是網(wǎng)關(guān)地址了,默認(rèn)192.168.1.1</param>
  /// <param name="UserName">用戶名</param>
  /// <param name="Passowrd">密碼</param>
  /// <returns></returns>
  private string LoadMACWanIP(string RouterIP,string UserName,string Passowrd)
  {
   CredentialCache cache = new CredentialCache();
   string url = "http://" + RouterIP + "/userRpm/StatusRpm.htm";
   cache.Add(new Uri(url), "Basic", new NetworkCredential(UserName, Passowrd));
   return SendRequest(url, gb2312, cache);
  }
}

MFC 獲取外網(wǎng)IP地址和MAC地址

ip地址獲取:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CString GetSystemIp(void)
{
 CString csSource;
 CString csAddress;
 CString csIPAddress;
 csIPAddress.Format(_T(" "));
 CInternetSession mySession(NULL,0);
 CHttpFile* myHttpFile=NULL;
 csAddress=_T("http://iframe.ip138.com/ic.asp");//ip138網(wǎng)頁 http://www.ip138.com/ip2city.asp
 myHttpFile=(CHttpFile*)mySession.OpenURL(csAddress);//讀取網(wǎng)絡(luò)地址
 while(myHttpFile->ReadString(csSource))
 { //循環(huán)讀取下載來的網(wǎng)頁文本
  //code 轉(zhuǎn)換
  char *pStr = (char*)csSource.GetBuffer(csSource.GetLength()); //取得str對象的原始字符串
  int nBufferSize = MultiByteToWideChar(CP_UTF8, 0,pStr, -1, NULL, 0); //取得所需緩存的多少
  wchar_t *pBuffer = (wchar_t*)malloc(nBufferSize * sizeof(wchar_t));//申請緩存空間
  MultiByteToWideChar(CP_UTF8, 0, pStr, -1 , pBuffer, nBufferSize*sizeof(wchar_t));//轉(zhuǎn)碼
  //MessageBox(pBuffer); //顯示
  csSource.Format(_T("%s"),pBuffer);
  free(pBuffer); //釋放緩存
 
  int begin=0;
  begin=csSource.Find(_T("["),0);
  if(begin!=-1)//如果找到"[", 則找"]" 中括號內(nèi)的文本則是 你的外網(wǎng)ip
  {
   int end=csSource.Find(_T("]"));
   csIPAddress.Format(_T("%s"),csSource.Mid(begin+1,end-begin-1));//提取外網(wǎng)ip
   return csIPAddress;
  }
 }
 return csIPAddress;
}

MAC地址獲取:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
CString GetMacAddress(void)
{
 //CString strIP,strGateWay,strSubnetMask;
 CString strMac;
 strMac.Format(_T(""));
 u_char pMac[6];
 PIP_ADAPTER_INFO adp = NULL;
 ULONG uLong=0;
 //為適配器申請內(nèi)存
 ::GetAdaptersInfo(adp,&uLong);
 adp = (PIP_ADAPTER_INFO)::GlobalAlloc(GPTR,uLong);
 
 //取得本地適配器結(jié)構(gòu)信息
 if(::GetAdaptersInfo(adp,&uLong) == ERROR_SUCCESS)
 {
  if(adp != NULL)
  {
   //strMacAdd.Format("%s",adp->Address);
   memcpy(pMac,adp->Address,6);
   strMac.Format(_T("%02X-%02X-%02X-%02X-%02X-%02X"),pMac[0],pMac[1],pMac[2],pMac[3],pMac[4],pMac[5]);
   //strGateWay.Format(_T("%s"),adp->GatewayList.IpAddress.String);// 網(wǎng)關(guān)
   //strIP.Format(_T("%s"),adp->IpAddressList.IpAddress.String);//IP
   //strSubnetMask.Format(_T("%s"),adp->IpAddressList.IpMask.String);//子網(wǎng)掩碼
   //MessageBox(strMac);
  }
 }
 return strMac;
}

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本一区二区三区中文字幕 | 欧美日韩视频 | 日韩精品在线观看免费 | se在线播放| 亚洲第十页 | 亚洲精品a | 99久久成人| 一级片在线免费观看视频 | 日韩激情一区二区 | 久久精品高清 | 五月天一区二区 | 亚洲自拍偷拍精品 | 欧美日在线 | 成年人在线看 | 精品二区 | 在线日韩 | 亚洲人视频在线 | 日本成片视频 | 亚洲一区二区久久 | 午夜不卡视频 | 综合久久久久 | 九九九在线 | 欧美亚洲三级 | 欧美在线观看一区 | 久久久久久久久久久影视 | 国产精品一级毛片在线 | 精品国产在 | 九九av| 成人免费黄色毛片 | 欧美激情视频一区二区三区在线播放 | 91综合在线观看 | 欧美日韩三级在线 | 欧美日韩亚洲一区二区 | 亚洲高清视频在线 | 国产欧美一区二区三区在线看 | 自拍偷拍av | 国产欧美中文字幕 | 欧美一区二区三区在线看 | 操久久 | 九九精品视频在线观看 | 日本中文字幕在线看 |