带着笔记本有时候在固定的地方工作,需要用到同一个的Ip地址。换个地方换个Ip,又要重新输一遍。

开始感觉这个过程很繁琐,因为是window工作环境,一开始想到了vbs脚本。

无意中发现了强大的netsh命令。。。。

下面分两个部分,先介绍netsh的基本用法,然后贴段vbs脚本实现自动配置IP地址功能。

netsh常见用法

  • 查看网络配置 netsh interface ip show {选项}
  • 配置接口IP/网关IP netsh interface ip set address "本地连接" static ip地址 子网掩码 网关
  • 配置自动换取IP地址 DNS地址及 wins地址

    netsh interface ip set address "本地连接" dhcp

    netsh interface ip set dns "本地连接" dhcp

    netsh interface ip set wins "本地连接" dhcp

  • 配置静态IP地址 DNS地址 及 wins地址

    netsh interface ip set address "本地连接" static ip地址

    netsh interface ip set dns "本地连接" static 子网掩码

    netsh interface ip set wins "本地连接" static 网关

  • 查看网络配置文件 netsh -c interface dump 使用管道 > 可导出为网络配置文件
  • 导入网络配置文件 netsh -f 文件位置 或者 netsh exec 文件位置

vbs实现配置脚本

strIP = "10.37.7.228"
strMask = "255.255.255.0"
strGW = "10.37.7.254"

strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array(strIP)
strSubnetMask = Array(strMask)
strGateway = Array(strGW)
strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
        WScript.Echo "IP地址已更改。"
    Else
        WScript.Echo "更改IP地址失败。"
    End If
Next

最新文章

  1. Python模块之day4
  2. 收到远程通知,怎么区分是点击通知栏提醒进去的还是在foreground收到的通知?
  3. Python: 测试函数是否被调用
  4. improve performance whilemaintaining the functionality of a simpler and more abstract model design of processor hardware
  5. [LeetCode]题解(python):063-Unique path II
  6. hdu1116
  7. JAVA - Blowfish加密出现java.security.InvalidKeyException: Illegal key size 解决方案
  8. Nginx实用教程(二):配置文件入门
  9. 第3阶段——内核启动分析之prepare_namespace()如何挂载根文件系统和mtd分区介绍(6)
  10. 自动修改博客CSS样式用的代码
  11. 从知乎首页用户操作入口学习到的CSS技巧 - 合理利用伪元素实现一些装饰样式
  12. OpenGL学习(3)——Shader
  13. codevs 2291 糖果堆
  14. Ball---hdu5821(排序)
  15. Java实例 Part5:面向对象入门
  16. xamarin RunOnUiThread
  17. String.Join
  18. iOS 错误提示
  19. android学习五---OpenCV for android环境搭建
  20. CoreThink开发(十三)增加页面加载动画

热门文章

  1. SQL 面试题及答案(一)
  2. 如何选择分类器?LR、SVM、Ensemble、Deep learning
  3. Link Aggregation and LACP with Open vSwitch
  4. (实用篇)php 文件夹删除,清除缓存程序
  5. jQuery关于Select的操作
  6. Spring学习笔记--spring+mybatis集成
  7. ZMMR106-批量更新PO交货日期
  8. phpstudy linux (lnmp,lamp)一键安装
  9. sql 语句累积
  10. viewpager中对fragment的操作