Delphi calls the Netsh command to modify the IP address

Source: Internet
Author: User
Tags get ip

Delphi calls the Netsh command to modify the IP address
Let's start by describing how Netsh commands are used:

Here are some simple instructions for you.
1.Show IP
1.1CMD Mode
Enter directly below the cmd
netsh interface ip show address
Also abbreviated as
netsh int ip sh ad
See if the instructions are similar to Cisco's NOS instructions! Very suspect is plagiarism of Cisco. 1.2Netsh Mode
You can also enter the Netsh command mode
netsh//enter to netsh mode
Netsh>int//Enter the interface sub-option.
INTERFACE>IP//Incoming to IP sub-option.
Interface Ip>show
Show address-Displays IP addresses.
Show config-Displays IP addresses and other data.
Show DNS-displays DNS server addresses.
Show ICMP-Show ICMP statistics
Show interface-Display IP interface statistics
Show IPAddress-show IP addresses
Show Ipnet-show IP Net-to-media corresponding
Show Ipstats-show IP stats
Show joins-show added multicast groups
Show offload-Show offload content
Show Tcpconn-Show TCP connection
Show Tcpstats-Show TCP statistics
Show Udpconn-Show UDP connection
Show Udpstats-Show UDP statistics
Show wins-Displays the WINS server addresses.
2.Set IP
The following are all the available directives.
The instructions in this content:
Set address-Sets the IP address or default gateway on the specified interface.
Set DNS-sets the DNS server mode and address.
Set wins-sets the WINS server mode and addresses. 2.1. Set IP Address
2.1.1.DHCP settings
If you want IP addresses to be entered by DHCP
Interface Ip>set AD "zone Connection" DHCP
or simply Write
Interface Ip>set AD "zone Connection" D2.1.2. Static IP Settings
2.1.2.1. Setting IP address and sub-gateways
Netsh-enter to netsh mode
Netsh>int-Enter the interface sub-option.
INTERFACE>IP-Enter the IP sub-option.
Interface Ip>set Address name = "Zone Connection" Source = static Addr = 10.2.2.100 Mask = 255.255.255.0
can be simply written
Interface Ip>set AD "zone connection" s 10.2.2.100 255.255.255.02.1.2.2. Set IP Routing
Interface Ip>set Address name = "Zone Connection" gateway = 10.2.2.254 gwmetric = 1
can be simply written
Interface Ip>set AD "zone Connection" ga=10.2.2.254 GW = 12.1.2.3 IP addresses and routes are also set
Interface Ip>set Address name = "Zone Connection" Source = static Addr = 10.2.2.100 Mask = 255.255.255.0 gateway = 10.2.2.254 GWME Tric = 1
can be simply written
Interface Ip>set AD "Area Connection" s 10.2.2.100 255.255.255.0 10.2.2.254 1 after setting up, remember to use SH AD to see the set of the right. 2.3 Setting up a DNS source
If it is obtained by DHCP, enter
Interface Ip>set DNS "zone connection" source=dhcp
If you are using static settings, enter
Interface Ip>set DNS name = "Zone Connection" Source = static Addr = 10.2.5.2
Add a second group of DNS, please enter
Interface Ip>add DNS name = "Zone Connection" addr = 10.2.5.32.4 Set wins source
If it is obtained by DHCP, enter
Interface Ip>set wins "zone connection" source=dhcp
If you are using static settings, enter
Interface Ip>set WINS name = "Zone Connection" Source = static Addr = 10.2.5.10
Add a second group of WINS, please enter
Interface Ip>add WINS name = "Zone Connection" addr = 10.2.5.17
3. Export/Import the network status settings
3.1 Export
Netsh-c interface Dump >c:/netset.txt
Of course, interface can be shortened to int,dump and simplified to D, so it becomes
netsh-c int D >c:/netset.txt
3.2 Import
Netsh-f C:/netset.txt can invoke the procedure in Delphi:
Set to get IP automatically:
Netshtxt: = ' netsh interface ip set address ' + ' "' + NetWork + '" ' + ' source=dhcp ';
WinExec (Pchar (netshtxt), sw_hide);
The following code sets the IP address and gateway:
Netshtxt: = ' netsh interface ip set address name= ' + ' "' + NetWork + '" ' + ' source=static addr= ' + ipaddress.ipstring + ' mask= ' + submask. ipstring;
WinExec (Pchar (netshtxt), sw_hide);
Gateway
Netshtxt: = ' netsh interface ip set address name= ' + ' "' + NetWork + '" ' + ' gateway= ' + defaultgateway.ipstring + ' Gwmet Ric=0 ';
WinExec (Pchar (netshtxt), sw_hide);
The use of Ipedit, this component, has been modified, has been basically used for IP address input and access. Originally downloaded from the Internet for the use of, can be used in the process will find a lot of problems.
Set up DNS:
Netshtxt: = ' netsh interface ip set DNS name= ' + ' "' + NetWork + '" ' + ' source=static addr= ' + firstdns.ipstring + ' Regi Ster=primary ';
WinExec (Pchar (netshtxt), sw_hide);
netsh interface ip add DNS name= "Local Area Connection" addr= the IP address of your DNS index=2
Netshtxt: = ' netsh interface ip add DNS name= ' + ' "' + NetWork + '" ' + ' addr= ' + seconddns.ipstring + ' index=2 ';
Note the second DNS above, add the command:
netsh interface ip add DNS name= "Local Area Connection" addr= the IP address of your DNS index=2
A third DNS:
netsh interface ip add DNS name= "local connection" addr= your DNS IP address index=3 late call winexec execution, feeling pretty good, Note After the build, use the GetAdaptersInfo function to check if the IP address is set correctly.
Many of the similar tools that are circulating on the web are this principle.

set to DHCP    
   winexec ( netsh    interface     ip    set    address    local connect 1    dhcp SW_ HIDE);

Set as manual IP
WinExec ( 'netsh interface IP set address local connection 1 static 192.168.1.189 255 .255.255. 0 192.168.1.1 1 ',sw_hide); Set IP address
ShellExecute (handle, ',' netsh interface ip set address ' + sregedit +
' static 192.168.0.1 255.255.255.0 192.168.0.10 1 ', nil,nil,sw_hide)

Delphi calls the Netsh command to modify the IP address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.