Use shell scripts to continuously change the IP address of the FreeBSD host

Source: Internet
Author: User

I wrote about a small automatic vote a year ago.ProgramBecause the website of the other party is limited to one IP address, only 10 votes can be cast per day, so this automatic voting program is mainly used to vote on the proxy server in the initial design stage, later, my colleague provided 30 IP addresses in the LAN.CodeIt's done, but it's really tiring to manually change the IP address in windows, and WMI programming in windows won't. Finally, find a non-FreeBSD machine and write a script, it is configured to run after every day, and the effect is good.

The script name for changing the IP address is cip_vote, which can be called as follows:
./Cipvote fxp0 iptable.txt

In this example, fxp0is the name of the network card. iptable.txt is a list of IP addresses that can be changed. Its format is:

210.77.79.201 255.255.255.128 210.77.79.255
210.77.79.202 255.255.255.128 210.77.79.255
...

The first column is the IP address to be changed, the second column is the subnet mask, and the third column is the broadcast address.

For more information about how to change the IP address, see the ifconfig online manual.Source code:

#! /Usr/local/bin/bash <br/> # first obtain the current IP settings, after the IP address operation is completed, it is restored to the current setting <br/> inet_ip = 'ifconfig $1 | awk '$0 ~ /* Inet */{print $2} ''<br/> inet_netmask = 'ifconfig $1 | awk' $0 ~ /* Inet */{print $4} ''<br/> inet_broadcast = 'ifconfig $1 | awk' $0 ~ /* Inet */{print $6} ''<br/> # Read the file content and set the IP address, netmask, read the broadcast address into the related array and save it <br/> temp = 'wc-L $ 2' <br/> declare-I = 0; <br/> declare-I linenumber = 'echo $ temp | awk '{print $1} ''<br/> declare-I n; <br/> while ["$ I "! = "$ Linenumber"] <br/> DO <br/> N = $ I + 1 <br/> ip_array [N] = 'head-N $2 | tail -N 1 | awk '{print $1} ''<br/> netmask_array [N] = 'head-N $2 | tail-N 1 | awk' {print $2} ''<br/> broadcast_array [N] = 'head-N $2 | tail-N 1 | awk '{print $3}'' <br/> I = $ I + 1 <br/> done <br/> # Use the ifconfig command to change the IP address, then perform the voting, and finally restore the previous IP settings of the host <br/> I = 0; <br/> while ["$ I "! = "$ Linenumber"] <br/> DO <br/> N = $ I + 1 <br/> echo "ifconfig $1 Inet $ {ip_array ['echo $ N' ]} netmask $ {netmask_array ['echo $ n']} broadcast $ {broadcast_array ['echo $ n']} "<br/> ifconfig $1 Inet $ {ip_array [' echo $ n']} netmask $ {netmask_array ['echo $ n']} broadcast $ {broadcast_array ['echo $ n']} <br/> route add default 210.77.79.254 </ p> <p> # Add the code to execute the operation <br/> I = $ I + 1 <br/> done <br/> # restore the code to the original setting. <br/> ifconfig $1 Inet $ inet_ip netmask $ inet_netmask broadcast $ inet_broadcast <br/> route add default 210.77.68.25

Related Article

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.