1. 希望有大佬可以开发一个切换有线网络和无线网络的插件...
  • Xinu 回复了此帖

    阿杰i
    可以做一个 切换的,不过有限制就是两个适配器不能都开着,必须是一个开,一个关,这样好像挺low的,没查到其它的命令能在两个连接的适配器中做切换

    阿杰i
    是windows吧, 只查到了windows的,可以做到切换,但是有个问题就是每次切换都需要弹窗确认一下,这个窗口我屏蔽不掉

    Xinu

    对的 我用的win10

    当然了如果你能ios 和 win 都适配最好啦 :)
    弹窗是指win10的自带弹窗吗 ? 只要功能实现我觉得这些都是些小问题 , 再点击确定啥的都可以, 反正都比我拔插网线来的舒服

    Xinu
    tks
    是不是可以考虑下 接入一点vpn什么的 科学上网啥的 :)

    • Xinu 回复了此帖

      阿杰i
      开玩笑那 你这严重超纲了
      https://wx1.sbimg.cn/2020/05/08/UTOOLS_1588950249622.png
      根据改变跃点来切换有线网络与无线网络连接,体验较好,无需关闭适配器,但是有的时候并不好用,实在是没查到这个自动跃点还有啥机制🤔

      1. 有线网络名与无线网络名要自己根据自己电脑的配置,没自动查是因为有的时候会有多个。尤其是有虚拟机的时候
      2. 运行方式可以配置到 快捷命令 插件中,以powershell运行,忽略输出
      3. 也可以保存到xx.ps1脚本中, 新建一个x.bat 内容为 powershell /path/to/xx.ps1,然后将x.bat添加到utools中
      param( $mode )
      
      # 定义有线网络与无线网络适配器名称 区分大小写
      $WiredNetworkName = "以太网 2";
      $WirelessNetworkName =  "WLAN";
      
      # 以管理员身份运行
      $currentWi = [Security.Principal.WindowsIdentity]::GetCurrent()
      $currentWp = [Security.Principal.WindowsPrincipal]$currentWi
       
      if( -not $currentWp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
      {
        $boundPara = ($MyInvocation.BoundParameters.Keys | foreach{
           '-{0} {1}' -f  $_ ,$MyInvocation.BoundParameters[$_]} ) -join ' '
        $currentFile = (Resolve-Path  $MyInvocation.InvocationName).Path
       
       $fullPara = $boundPara + ' ' + $args -join ' '
       Start-Process "$psHome\powershell.exe"   -ArgumentList "$currentFile $fullPara"   -verb runas
       return
      }
      
      # 获取有线网络跃点及索引
      $WiredNetwork = Get-NetIPInterface | ? {$_.AddressFamily -eq "IPv4"} | ? {$_.InterfaceAlias -eq $WiredNetworkName} | select -Property ifIndex, InterfaceMetric, ConnectionState;
      # 获取无线网络跃点及索引;
      $WirelessNetwork = Get-NetIPInterface | ? {$_.AddressFamily -eq "IPv4"} | ? {$_.InterfaceAlias -eq $WirelessNetworkName} | select -Property ifIndex, InterfaceMetric, ConnectionState;
      # 定义通知函数
      [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");
      function ShowNotify($title, $content, $ico) {
          $obj = New-Object System.Windows.Forms.NotifyIcon;
          $path = Get-Process -id $pid | Select-Object -ExpandProperty Path;
          $icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path);
          $obj.Icon = $icon;
          $obj.BalloonTipIcon = $ico;
          $obj.BalloonTipText = $content;
          $obj.BalloonTipTitle = $title;
          $obj.Visible = $True;
          $obj.ShowBalloonTip(10000);
      }
      
      # 重置模式 重置跃点为自动模式
      if ($mode -eq "reset") {
          if($WiredNetwork) {
              Set-NetIPInterface -InterfaceIndex $WiredNetwork.ifIndex -AutomaticMetric Enabled
          }
          if($WirelessNetwork) {
              Set-NetIPInterface -InterfaceIndex $WirelessNetwork.ifIndex -AutomaticMetric Enabled
          }
          ShowNotify '提示' '网络连接行为已重置为默认状态' 'Info';
          exit;
      }
      
      # 调换跃点
      if ($WiredNetwork.ConnectionState -eq "Connected" -and $WirelessNetwork.ConnectionState -eq "Connected") {
          $w = $WiredNetwork.InterfaceMetric;
          $wl = $WirelessNetwork.InterfaceMetric;
          if ($w -lt $wl) {
              # Set-NetIPInterface -InterfaceIndex $WirelessNetwork.ifIndex -InterfaceMetric 11
              # Set-NetIPInterface -InterfaceIndex $WiredNetwork.ifIndex -InterfaceMetric 24
              Set-NetIPInterface -InterfaceIndex $WirelessNetwork.ifIndex -InterfaceMetric ($w + 1)
               Set-NetIPInterface -InterfaceIndex $WiredNetwork.ifIndex -InterfaceMetric $wl
               Set-NetIPInterface -InterfaceIndex $WirelessNetwork.ifIndex -InterfaceMetric $w
          } else {
             # Set-NetIPInterface -InterfaceIndex $WiredNetwork.ifIndex -InterfaceMetric 11
             # Set-NetIPInterface -InterfaceIndex $WirelessNetwork.ifIndex -InterfaceMetric 24
              Set-NetIPInterface -InterfaceIndex $WiredNetwork.ifIndex -InterfaceMetric ($wl + 1)
              Set-NetIPInterface -InterfaceIndex $WirelessNetwork.ifIndex -InterfaceMetric $w
             Set-NetIPInterface -InterfaceIndex $WiredNetwork.ifIndex -InterfaceMetric $wl
          }
          ShowNotify '提示' '网络切换成功' 'Info';
      } else {
          ShowNotify '警告' '当前只有单一网络连接,无法切换' 'Warning';
          exit;
      }

      Xinu
      tks
      哈哈 只是说提供个建议撒
      好的 我待会试下 能不能切换 ...

        Xinu
        好像没有成功
        1. 把脚本复制到快捷命令中运行 显示这个
        on : 无法将“on”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试
        一次。
        所在位置 C:\Users\Jie\AppData\Local\Temp\QuickCommandTempScript.ps1:1 字符: 1
        + on
        + ~~
        + CategoryInfo : ObjectNotFound: (on:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
        2. 把脚本文件复制到快捷命令中 快捷命令 好像没什么反应
        3. 把脚本放到了 bat 里面 双击执行 cmd 一闪即逝 ip 也没切换成功 ...

        • Xinu 回复了此帖

          阿杰i
          把这个文件里面俩名字更改成你的,然后复制到一个1.ps1的文件中,然后在cmd下执行 powershell 1.ps1 试试,看有没有提示啥的

            说点什么吧...
            闽ICP备18007474号