找回密码
 加入
搜索
查看: 3663|回复: 9

[网络通信] 有没有办法通过VPN连接名来获取VPN连接的IP?

  [复制链接]
发表于 2011-7-29 23:02:01 | 显示全部楼层 |阅读模式
用dllcall调用来获取IP过程中会跟PPPOE混淆!
用@ipaddress 来获取,在多网卡下,完全没办法。
有没有办法通过VPN连接名来获取VPN连接的IP?
 楼主| 发表于 2011-7-30 00:10:02 | 显示全部楼层
本帖最后由 freedom 于 2011-7-30 00:11 编辑

我找到一个可以通过WMI直接获取上网网关的。但是没看懂。。。
这个就比较精确,PPTP,PPPOE,NAT都能很精确的获取到上网的网关。

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colNicConfigs = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
                For $objNicConfig In $colNicConfigs
     If Not ($objNicConfig.DefaultIPGateway) = " " Then
      For $i = 0 To UBound($objNicConfig.DefaultIPGateway) -1
        $WG=$objNicConfig.DefaultIPGateway($i)
      Next
  EndIf
  Next
  MsgBox (0,0,$wg)
发表于 2011-8-3 01:43:50 | 显示全部楼层
vpn 的话只能获取到vpn分配IP和网关
发表于 2011-8-3 01:47:28 | 显示全部楼层

#include <rasapi.au3>
$aEntry = _RasEnumEntries()
$aConn = _RasEnumConnections()
If Not $aEntry[0][0] = "" Then
        If Not $aConn[0][0] = "" Then
                For $i = 1 To $aConn[0][0]
                        If $aConn[$i][2] = "VPN" Then
                                _ArrayDisplay($aConn)
                                $aSen = _RasGetConnectionIpAddresses($aConn[$i][0])
                                _ArrayDisplay($aSen)
                                MsgBox(0, "Gateway:" & $aSen[1], "IP:" & $aSen[0])
                        EndIf
                Next
        EndIf
EndIf


其中用到的udf:http://www.autoitx.com/forum.php?mod=viewthread&tid=17179
 楼主| 发表于 2011-8-3 03:32:06 | 显示全部楼层
回复 4# xayle


    非常感谢,这个例子在WINXP,及WIN7下,通过路由上网已测试成功。明天去试下ADSL。
发表于 2011-8-3 03:39:57 | 显示全部楼层
回复 5# freedom


    如果是ADSL的话
要把 VPN 这里改成 PPPoE
发表于 2020-11-29 14:05:05 | 显示全部楼层
学习一下,如何获取
发表于 2020-11-29 14:05:37 | 显示全部楼层
学习一下,如何获取
发表于 2020-11-29 14:05:57 | 显示全部楼层
为什么这里回复,这么高的分
发表于 2021-1-6 09:59:36 | 显示全部楼层
学习一下,如何获取
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 05:19 , Processed in 0.085165 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表