獲得本機IP和DNS方法。

2021-06-20 05:10:53 字數 426 閱讀 9285

載自屢試不爽的某位大神。

利用tcp傳送報文,給已知存在的ip傳送tcp連線,可以獲得本地有效ip。

///

/// 獲取當前使用的ip

///

///

///

/// 獲取本機主dns

///

///

/// 程式名

/// 輸入引數

///

using (system.io.streamreader sr = new system.io.streamreader(proc.standardoutput.basestream, encoding.default))

if (!proc.ha***ited)

return txt;}}

catch (exception ex)

}

獲得本機IP

1.簡單伺服器 include pragma comment lib,ws2 32.lib wsadata wsd static uint port 1 uint listen lpvoid pparam sserver socket af inet,sock stream,ipproto tcp ...

獲得本機IP和MAC位址

用c 獲得本機ip和 mac類為管理物件的集合,上例中由檢索物件返回管理物件集合賦值給它.using system using system.collections.generic using system.text using system.net using system.management ...

使用Python獲得本機IP位址

使用撥號上網的話,一般都有乙個本地ip和乙個外網ip,使用python可以很容易的得到這兩個ip 使用gethostbyname和gethostbyname ex兩個函式可以實現 import socket localip socket.gethostbyname socket.gethostnam...