这几天遇到个烦心事,每次开机之后都要去手动去设置一下IP地址,一大串的数字还是有点麻烦,于是就想写个批处理文件设置IP

注意:在DOS下设置IP时需要管理员权限运行

1.查看机子设置IP需要用到的名字

名字是Ethernet

2.查看机子在DOS下设置IP和DNS命令的格式

C:\Windows\system32>netsh
netsh>interface
In future versions of Windows, Microsoft might remove the Netsh functionality
for TCP/IP.

Microsoft recommends that you transition to Windows PowerShell if you currently
use netsh to configure and manage TCP/IP.

Type Get-Command -Module NetTCPIP at the Windows PowerShell prompt to view
a list of commands to manage TCP/IP.

Visit http://go.microsoft.com/fwlink/?LinkId=217627 for additional information
about PowerShell commands for TCP/IP.
netsh interface>ip
netsh interface ipv4>set address
One or more essential parameters were not entered.
Verify the required parameters, and reenter them.
The syntax supplied for this command is not valid. Check help for the correct syntax.

Usage: set address [name=]<string>
[[source=]dhcp|static]
[[address=]<IPv4 address>[/<integer>] [[mask=]<IPv4 mask>]
[[gateway=]<IPv4 address>|none [gwmetric=]<integer>]
[[type=]unicast|anycast]
[[subinterface=]<string>]
[[store=]active|persistent]

Parameters:

Tag Value
name - Interface name or index.
source - One of the following values:
dhcp: Enables DHCP for configuring IP addresses for
the specified interface.
static: Disables DHCP for configuring IP addresses for
the specified interface. This value must be
specified if an address or a gateway is being
configured.
address - IPv4 address to add or modify, optionally followed by
the subnet prefix length.
mask - The IP subnet mask for the specified IP address.
gateway - One of the following values:
<IPv4 address>: A specific default gateway for the
static IP address you are setting.
none: No default gateways are set. This is the default.
gwmetric - The metric for the default gateway. This field should
be set only if gateway is specified.
type - One of the following values:
unicast: Marks the address as a unicast address.
This is the default.
anycast: Marks the address as an anycast address.
subinterface - LUID of the subinterface on which the default gateway
exists. This parameter is only needed on interfaces
with multiple subinterfaces.
store - One of the following values:
active: Set only lasts until next boot.
persistent: Set is persistent. This is the default.

Remarks: Used to enable or disable DHCP for IP address configuration.
Also removes any previous static IP addresses and default gateways,
and can add a new static IP address and default gateway.

Examples:

set address name="Wired Ethernet Connection" source=dhcp
set address "Wired Ethernet Connection" static 10.0.0.9 255.0.0.0 10.0.0.1 1

netsh interface ipv4>set dns
One or more essential parameters were not entered.
Verify the required parameters, and reenter them.
The syntax supplied for this command is not valid. Check help for the correct syntax.

Usage: set dnsservers [name=]<string> [source=]dhcp|static
[[address=]<IP address>|none]
[[register=]none|primary|both]
[[validate=]yes|no]

Parameters:

Tag Value
name - The name or index of the interface.
source - One of the following values:
dhcp: Sets DHCP as the source for configuring DNS
servers for the specific interface.
static: Sets the source for configuring DNS servers
to local static configuration.
address - One of the following values:
<IP address>: An IP address for a DNS server.
none: Clears the list of DNS servers.
register - One of the following values:
none: Disables Dynamic DNS registration.
primary: Register under the primary DNS suffix only.
both: Register under both the primary DNS suffix, as
well as under the connection-specific suffix.
validate - Specifies whether validation of the DNS server setting
will be performed. The value is yes by default.

Remarks: Sets DNS server configuration to either DHCP or static mode. Only
when source is 'static', is the 'addr' option also available for
configuring a static list of DNS server IP addresses for the
specified interface. If Validate switch is yes, then
the newly set DNS server is validated.

Examples:

set dnsservers name="Wired Ethernet Connection" source=dhcp
set dnsservers "Wired Ethernet Connection" static 10.0.0.1 primary

netsh interface ipv4>

格式分别是

set address name="Wired Ethernet Connection" source=dhcp  (自动获取IP)
  set address "Wired Ethernet Connection" static 10.0.0.9 255.0.0.0 10.0.0.1 1 (静态设置)

set dnsservers name="Wired Ethernet Connection" source=dhcp (自动获取DNS)
  set dnsservers "Wired Ethernet Connection" static 10.0.0.1 primary (静态设置)

3.写批处理文件

在家里时自动分配IP

HOME.bat

netsh interface ip set address "Ethernet" source=dhcp
netsh interface ip set dns "Ethernet" source=dhcp

上班时

WORK.bat

netsh
netsh interface ip set dnsservers "Ethernet" static 202.103.44.151

4.管理员权限运行

修改后的IP和DNS

有了这两个文件之后就不用手动配啦

.bat文件设置IP、DNS的更多相关文章

  1. bat文件设置ip自动和静态ip切换

    下载地址:https://i.cnblogs.com/Files.aspx win10系统: @echo off cd /d %~dp0 %1 start "" mshta vbs ...

  2. PC问题-使用BAT方法设置IP地址

    ::------以下为批处理文件内容---- @echo off ::set slection1= set/p slection1=请输入IP地址: netsh interface ip set ad ...

  3. BAT-使用BAT方法设置IP地址

    ::------以下为批处理文件内容---- @echo off ::set slection1= set/p slection1=请输入IP地址: netsh interface ip set ad ...

  4. bat文件设置环境变量

    ::获取管理员权限 @echo off%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute(" ...

  5. windows bat文件设置环境变量

    主要是SET和SETX这个两个命令 SETX 永久设置用户环境变量 SETX /M 永久设置系统环境变量 SET 临时设置用户环境变量 SET /M 临时设置系统环境变量

  6. bat文件设置环境变量脚本

    :: 获取管理员权限 @echo off % mshta vbscript:CreateObject()(window.close)&&exit cd /d "%~dp0&q ...

  7. 做一个自动修改本机IP和mac的bat文件

    原文:做一个自动修改本机IP和mac的bat文件 1.ip bat修改理论探讨 前两天我突然萌生了一个念头:能不能做一个小程序来实现自动配置或修改IP和mac,达到一键搞定的目的,这样尤其适合那些带着 ...

  8. windows命令行设置IP与DNS

    用dos命令修改IP等本地连接属性 平时我们改IP通常都在是窗口界面本地连接直接修改, 那在命令行也可以设置IP地址?当然可以,这里要用到netsh命令 .点击“开始”->“运行”,输入“cmd ...

  9. 批处理文件设置IP以及DNS

    先附上批处理文件代码(批处理文件怎么创建自己另行百度,这里不再赘述) Echo offecho ==============请输入序号修改办公区===========echo *********1.家 ...

随机推荐

  1. 仿苹果短信(微信 ,qq)左划弹出菜单

    难点: 1.功能的实现,左划.ListView的复用 2.单行显示,多行显示 3.ListView分割线.点击阴影,上下滑动左右滑动无阴影.多点触控改为单点触控 4.融球动画 http://blog. ...

  2. JQuery实现超链接鼠标提示效果

    一.第一种方法用Jquery<p><a href="http://www.nowamagic.net/" class="tooltip" ti ...

  3. Laravel 目录结构分析

    根目录结构 /app/bootstrap/public/vendorartisancomposer.jsonserver.php 1./app 整个Laravel 目录中最需要我们注意的地方,包含设置 ...

  4. Apache Mina(二)

    在mina的源码,整个框架最核心的几个包是 : org.apache.mina.core.service :IoService.IoProcessor.IoHandler.IoAcceptor.IoC ...

  5. ASIHTTPRequest异步请求

    我们运行程序,如果网速很慢,查询的时候会一直黑屏,直到请求结束画面才出现,这样用户体验很不好.因此同步请求一般只是在某个子线 程中使用,而不在主线程中使用.异步请求的用户体验要比同步请求好,因此一般情 ...

  6. leetcode--007 word break I

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+4AAAC5CAIAAAA55fI7AAAZa0lEQVR4nO3dPW7bQIMG4L2MT6B7+A

  7. iOS搜索框UISearchBar 分类: ios技术 2015-04-03 08:55 82人阅读 评论(0) 收藏

    当你在seachBar中输入字母之前的时候,只是用鼠标选中searchBar的时候,如图 终端输出截图如下:(这个时候调用先shouldBeginEditing,之后调用didBeginEditing ...

  8. python 错误AttributeError: 'module' object has no attribute 'AF_INET'

    写了一个简单的python socket的程序.运行时,报错如下 原因:文件的命名与Python的function的命名冲突 修改名称后,发现还是无法运行,检查目录下面是否有 这样子的一个文件,删除即 ...

  9. osgEarth学习笔记(转载)

    osgEarth学习笔记1.        通过earth文件创建图层时,可以指定多个影像数据源和多个高程数据源,数据源的顺序决定渲染顺序,在earth文件中处于最前的在渲染时处于最底层渲染:所以如果 ...

  10. Mysql中如何创建、删除授权用户

    在mysql数据库下使用create user创建新用户,例如: 新创建后的用户没有任何授权.使用grant命令授权xushouwei访问数据库databaseweb下的所有表,密码为xsw12345 ...