{"id":290,"date":"2016-11-03T22:07:27","date_gmt":"2016-11-03T14:07:27","guid":{"rendered":"http:\/\/blog.haostudio.net\/hwp\/?p=290"},"modified":"2017-07-25T00:06:28","modified_gmt":"2017-07-24T16:06:28","slug":"shell-tips-ipv4-address-%e5%88%a4%e6%96%b7","status":"publish","type":"post","link":"https:\/\/blog.haostudio.net\/hwp\/shell-tips-ipv4-address-%e5%88%a4%e6%96%b7\/","title":{"rendered":"[Shell Tips] IPv4 address \u5224\u65b7"},"content":{"rendered":"<!--more-->\n<h3>IPv4 address \u5224\u65b7<\/h3>\n<pre><code>\u627e\u51fa\/etc\/hosts \u4e2d\u542b\u6709IP \u7684\u6587\u5b57\u5217\ngrep -E &#039;[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}&#039; \/etc\/hosts\n\n\u53d6\u51fa\/etc\/hosts \u4e2d\u542b\u6709IP \u7684\u90e8\u5206\ngrep -Eo &#039;[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}&#039; \/etc\/hosts\n\n\u7528bash\u5224\u65b7\u5b57\u4e32\u662f\u5426\u70baIPV4\nif [ ` echo $ip | grep -E &#039;^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$&#039;  | grep -o &quot;\\.&quot; | wc -l` -eq 3 ];\nthen \n    ipv4=true\nelse \n    ipv4=false\nfi\n<\/code><\/pre>\n<p>\u53c3\u8003\u4f86\u6e90:<\/p>\n<ol>\n<li><a href=\"http:\/\/superuser.com\/questions\/202818\/what-regular-expression-can-i-use-to-match-an-ip-address\">What regular expression can I use to match an IP address?<\/a><\/li>\n<li><a href=\"http:\/\/www.rtfiber.com.tw\/~changyj\/shell\/check_ip.pdf\">Shell \u642d\u914d\u6b63\u898f\u5f0f\u4f86\u6aa2\u6e2c\u4e00\u5b57\u4e32\u662f\u5426\u70baIPv4 \u683c\u5f0f\u4e4bIP<\/a><\/li>\n<\/ol>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[61],"class_list":["post-290","post","type-post","status-publish","format-standard","hentry","category-shell-script","tag-shell-script"],"_links":{"self":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/comments?post=290"}],"version-history":[{"count":2,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/290\/revisions"}],"predecessor-version":[{"id":385,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/posts\/290\/revisions\/385"}],"wp:attachment":[{"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/media?parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/categories?post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.haostudio.net\/hwp\/wp-json\/wp\/v2\/tags?post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}