有誰知道(PC的你的工作)的R函數,能夠檢索自己的IP地址?這將是非常有益的!提前謝謝了。從R中檢索自己的IP地址的函數?
15
A
回答
23
可以發出一個system()
命令操作系統:
- 在Windows中可以使用
ipconfig
- 在Linux中,使用
ifconfig
例如,在Windows嘗試調用system()
與參數intern=TRUE
的結果返回給R:
x <- system("ipconfig", intern=TRUE)
這將返回:
x
[1] ""
[2] "Windows IP Configuration"
[3] ""
[4] ""
[5] "Wireless LAN adapter Wireless Network Connection:"
[6] ""
[7] " Connection-specific DNS Suffix . : tbglondon.local"
[8] " Link-local IPv6 Address . . . . . : fe80::c0cb:e470:91c7:abb9%14"
[9] " IPv4 Address. . . . . . . . . . . : 10.201.120.184"
[10] " Subnet Mask . . . . . . . . . . . : 255.255.255.0"
[11] " Default Gateway . . . . . . . . . : 10.201.120.253"
[12] ""
[13] "Ethernet adapter Local Area Connection:"
[14] ""
[15] " Connection-specific DNS Suffix . : tbglondon.local"
[16] " Link-local IPv6 Address . . . . . : fe80::9d9b:c44c:fd4d:1c77%11"
[17] " IPv4 Address. . . . . . . . . . . : 10.201.120.157"
[18] " Subnet Mask . . . . . . . . . . . : 255.255.255.0"
[19] " Default Gateway . . . . . . . . . : 10.201.120.253"
[20] ""
[21] "Tunnel adapter Local Area Connection* 13:"
[22] ""
[23] " Media State . . . . . . . . . . . : Media disconnected"
[24] " Connection-specific DNS Suffix . : "
[25] ""
[26] "Tunnel adapter isatap.tbglondon.local:"
[27] ""
[28] " Media State . . . . . . . . . . . : Media disconnected"
[29] " Connection-specific DNS Suffix . : tbglondon.local"
[30] ""
[31] "Tunnel adapter Teredo Tunneling Pseudo-Interface:"
[32] ""
[33] " Media State . . . . . . . . . . . : Media disconnected"
[34] " Connection-specific DNS Suffix . : "
現在你可以使用grep
與IPv4
找到行:
x[grep("IPv4", x)]
[1] " IPv4 Address. . . . . . . . . . . : 10.201.120.184"
[2] " IPv4 Address. . . . . . . . . . . : 10.201.120.157"
而且只提取IP地址:
z <- x[grep("IPv4", x)]
gsub(".*? ([[:digit:]])", "\\1", z)
"10.201.120.184" "10.201.120.157"
-1
這檢索正是你想要的:
system('ipconfig getifaddr en0')
192.168.1.73
+0
您的命令在R或CMD窗口(在我的Window 7工作站上)中不起作用。你能重新測試一下嗎?可能只是針對你的機器?它只是返回一個廣泛的'ipconfig'命令幫助手冊。 –
3
我最近創建使用ipify.org
做這個確切的事情最小包裝。
用法很簡單,你可以安裝使用devtools
和github上。
library(devtools) install_github("gregce/ipify")
一旦安裝,其一樣容易加載庫和一個函數調用...
library(ipify) get_ip()
0
雖然@andrie非常深入淺出解釋它,我相信它幫助我們瞭解它的功能很多。
所以從那裏只有共享一個襯墊代碼,而無需安裝任何其他程序包。
gsub(".*? ([[:digit:]])", "\\1", system("ipconfig", intern=T)[grep("IPv4", system("ipconfig", intern = T))])
希望這會有所幫助!
相關問題
- 1. 檢查您自己的IP地址
- 2. ip地址檢索
- 3. 檢索的IP地址與RKA IP地址的中間件
- 4. 如何使用WinINet函數獲取自己的IP地址
- 5. 獲取自己的IP地址
- 6. 獲取我自己的IP地址
- 7. 通過nslookup命令搜索我自己的IP地址從許多其他ip
- 8. 從數據包中檢索遠程IP地址的準確性
- 9. 從Tomcat會話ID檢索IP地址?
- 10. 從DAO層檢索IP地址
- 11. 如何從Grails中的IP地址檢索地理位置?
- 12. 代碼檢測Android設備自己的IP地址?
- 13. 在我自己的IP地址上使用Linux NAT我的IP地址是
- 14. 使用PHP的gethostbyname檢索IP地址()
- 15. 如何檢索Meteorjs上的IP地址?
- 16. 檢索從pymongo MongoDB的IP地址數據
- 17. 在Go中,如何從開放的TCPConn *中檢索IP地址?
- 18. 不能從公共ip地址訪問我自己的moodle
- 19. 如何從一個struct addrinfo獲取我自己的IP地址
- 20. 從我自己的Android應用程序設置Android IP地址
- 21. 如何從Java的HTTP標頭中檢索IP地址
- 22. URL路徑中的資源是否有自己的IP地址?
- 23. 從ExE或Bin文件中檢索函數的地址
- 24. 在R中返回自己的函數?
- 25. IP地址映射中的R
- 26. Word VBA檢索IP地址「靜默」
- 27. PHP curl,檢索服務器IP地址
- 28. 如何檢索遠程IP地址?
- 29. 檢查IP地址
- 30. vb6從本地主機或遠程IP地址檢索IPV6
和UNIX下'ifconfing'像系統... – agstudy
@agstudy謝謝。回答編輯 – Andrie
非常感謝你! – rdatasculptor