Shell Note: Get the native IP address

Source: Internet
Author: User
#!/bin/bash#2.sh# Write a shell script to get the network address of this machine. #比如: The IP address of this machine is: 192.168.100.2/255.255.255.0, then its network address is 192.168.100.1/255.255.255.0# Note: Bcast with the previous IP address is two spaces, So make sure to delete all two blanks.
#grep后面的搜索词加不加引号都可以, if it is a longer, there are spaces, such as inet addr, just add quotation marks, only mask can not add
#之所以搜索inet addr Because, just search inet, and IPv6 's address.
ip= ' Ifconfig eth0 | grep ' inet addr ' | Sed ' s/^.*addr://g ' |sed ' s/ bcast:.*$//g ' mask= ' ifconfig eth0 | grep MASK |sed ' s/^.*mask://g ' echo ' $IP/$MASK ' exit

  

Shell Note: Get the native IP address

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.