archer05 发表于 2018-8-30 07:54:47

shell获取ip地址 . --erikxue 薛忠权

#!/bin/sh# Shell script scripts to read ip address# -------------------------------------------------------------------------# Copyright (c) 2005 nixCraft project # This script is licensed under GNU GPL version 2.0 or above# -------------------------------------------------------------------------# This script is part of nixCraft shell script collection (NSSC)# Visit http://bash.cyberciti.biz/ for more information.# -------------------------------------------------------------------------# Get OS nameOS=`uname`IO="" # store IPcase $OS in  
   Linux) IP=`ifconfig| grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
  
   FreeBSD|OpenBSD) IP=`ifconfig| grep -E 'inet.' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
  
   SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
  
   *) IP="Unknown";;esacecho "$IP"


页: [1]
查看完整版本: shell获取ip地址 . --erikxue 薛忠权