1 obtain IP Address

echo StartChangeIPFile
echo Get the hostname
for /f %%i in ('hostname') do (set pcName=%%i)
::ping %pcName% -4
echo Start getting IP And keep it in c:\tmp\ip.txt In file
for /f "tokens=2 delims=[]" %%i in ('ping %pcName% -4^|findstr "%pcName%"') do (set ip=%%i
echo %%i>c:\tmp\ip.txt)
echo replace content
for /f "tokens=* " %%i in (c:\tmp\ip.txt) do set "ip=%%i"
if defined ip (
echo Variable ip The value of is not empty
) else (echo Variable ip Null value
pause)
:: The following is to modify a file , Replace the specified content with IP, Attention is not getting IP That's the best part
:: It's used here sed command , If used , It can be downloaded from the Internet Windows The version is just
sed "s/=.*IP/=%ip%/g" %DirPath%agent_net.cfg >c:\tmp\agent_net.cfg
echo Coverage
copy /y c:\tmp\agent_net.cfg %DirPath%agent_net.cfg

If the host is hosts Add... To the document 127.0.0.1 hostname analysis , Then it is possible to obtain by using the above method ip The address is 127.0.0.1,

We can use powershell To get IP:

Reference resources :Get Current IP Address

 #Here is a quick way to get all IP addresses assigned to your #computer:
#requires -Version
$ipaddress = [System.Net.DNS]::GetHostByName($null)
Foreach ($ip in $ipaddress.AddressList)
{
$ip.IPAddressToString
}
If you replace $null with a hostname (like "server123"), you can retrieve the IP address(es) assigned to that computer instead, too.
#And if you are just interested in IPv4 addresses, try this:
#requires -Version
$ipaddress = [System.Net.DNS]::GetHostByName($null)
foreach($ip in $ipaddress.AddressList)
{
if ($ip.AddressFamily -eq 'InterNetwork')
{
$ip.IPAddressToString
}
}

2 About For loop

It's more comprehensive to refer to others , as follows :

BAT Batch processing removes everything before or after the specified character

Use it directly window Just help , open cmd, Input for /?.

The more common ones are as follows ( Direct operation bat File replacement below % by %%, If you write directly from the command line , Direct order % Here's how it works )

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]

FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

3 Post a few more grammatical sentences

1 if……else

if exist "D:\" (
echo aaa
 goto DecompressOnDiskD
) else (
goto DecpmpressOnDiskC
)

2 Scripts call other scripts , Never use goto, Use call, Otherwise, the execution will be interrupted

3 Variable assignment is set

4 Jump inside the program , It's best to use labels , And then use goto Jump

goto ChangeIp
:changeIp
echo StartChangeIPFile

5 Windows The escape character is ^, as follows

set "str1=^<WorkingDirectory^>%cd%^<^/WorkingDirectory^>"

Windows More articles about scripts

  1. VBScript: Windows Script host Introduction

    Windows Script host (Windows Script Host, WSH) It's a Windows Management tools .WSH Create a main environment for scripts to run ,WSH Enable scripts to use objects and services , And provide guidelines for script execution .WSH also ...

  2. c# Executing scripts dynamically , Related script engines .

    Jint   Embedded javascript Script support engine , It's been updated all the time , Support for various methods is also better , Sure C# Interaction . https://github.com/sebastienros/jint Jurass ...

  3. Imagine again Windows 8 Store Apps (70) - Other : File compression and decompression , And Windows Store related operations , app And web, How many? Core Application , The life cycle of the page and the life cycle of the program

    [ Source download ] Imagine again Windows 8 Store Apps (70) - Other : File compression and decompression , And Windows Store related operations , app And web, How many? Core Application , Page ...

  4. Windows Script

    Recently, project testing is quite troublesome , To start several command window , It's a little cumbersome, like hand tapping , So I studied windows Script , Implement the following functions : Are you lazy , I'm too lazy to remember the order of parameter meanings , So you need friendly parameter prompts : Start according to the number of parameters ...

  5. windows Script (VBS) And cmd The magic of the command line

    windows Script (VBS) And cmd The magic of the command line (2009-08-06 13:40:55) Reprint ▼ label : Script cmd Command line vbs js Simple The formula windows it classification :  Computer Script ...

  6. modify host Specify the domain name to ip,Windows Script vs Linux Script

    modify host Specify the domain name to ip,Windows Script vs Linux Script One ,Windows System modification hosts file Windows Under the system hosts file location :C:\Windows\System32\driver ...

  7. windows Script -CMD and Batch

    One .DOS,CMD and batch DOS It's the disk operating system ( english :Disk Operating System) Abbreviation , It's an operating system on a personal computer . from 1981 Until 1995 Year of 15 Year ,DOS stay IBM PC ...

  8. windows Script configuration ip Address

    background : Work often involves debugging equipment , Each time you manually configure static ip Address , After the configuration, it needs to be changed back , Sometimes in order to continuously debug multiple devices , Back and forth manually change ip, It's a real hassle . reflection : The thought of windows Scripts , You can use script files to achieve ...

  9. window FILES——windows File management related examples

    C Language has a set of file management program .C++ Language also has its own file management program .windows Of course, the system also has its own file management scheme . For ordinary char The solution for type based characters is the same with either solution , But for wide characters ...

Random recommendation

  1. Prince2 The seven principles (4)

    Let's review ,PRINCE2 The seven principles are continuous business verification , Experience learning , Roles and responsibilities , Manage by stages , Exception management , Focus on the product , Tailoring . Fourth principle : Manage by stages . Stage management actually provides the corresponding control in the project life cycle for the senior management ...

  2. ( turn )ViewPager,ScrollView nesting ViewPager Slide conflict resolution

    ViewPager,ScrollView nesting ViewPager Slide conflict resolution This article mainly explains several problems Give a brief introduction to View Event distribution mechanism of Ideas and methods to solve the sliding conflict of events ScrollView Embedded inside ...

  3. Raspberry pie 2 win 10 IOT

    Setting up Windows 10 for IoT on your Raspberry Pi This week at the BUILD conference in San Francisc ...

  4. POJ1017 packets

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 48911   Accepted: 16570 Descrip ...

  5. About C++ Some discussions on arrays

    What is the name of the array ? int main() { , , , , }; int *pnumber = number; cout << sizeof(number) << endl; c ...

  6. Shopping mall project arrangement ( 3、 ... and )JDBC Additions and deletions

    The increase in the commodity list , modify , Delete , The addition of order forms , confirm , User table view , The increase of log table , see Commodity TABLE CREATE TABLE statement : create table TEST.GOODS_TABLE ( gid NUMBER not null ...

  7. RabbitMQ Message queue introduction Chapter one

    RabbitMQ : Official website :https://www.rabbitmq.com/ GitHub:https://github.com/rabbitmq?q=rabbitmq The first step is to install : Click on   htt ...

  8. JVM Parameter description

    java The virtual machine starts with many startup parameters ,Java The command itself is a multi parameter startup command . So specific JVM What parameters are included in the startup ? This article aims at java8 Do a summary interpretation of the situation , Contains most common and uncommon command parameters , excessively ...

  9. python Lists and tuples in

    1. What is a list Definition : Objects that can hold objects stay python Use in [] To describe the list , The inner elements are separated by commas . There is no requirement for data types , The list has indexes and slices . It's the same as a string . 2. Related operations of adding, deleting, modifying and checking section List and ...

  10. vmware transmission (vmdb) error -32:pipe:read failed resolvent

    Excerpt from : http://www.myzhenai.com.cn/post/1088.html transmission (vmdb) error -32:pipe:read failed resolvent   Original content , Reprint please indicate the source :htt ...