linux 得到内网外网ip
2013-03-18 23:39
337 查看
原文
Create simple bash function (example int-ip) with following command.
Create simple bash function (example int-ips) with following command.
已验证
Create simple bash function (example ext-ip) with following command.
Create simple bash function (example ext-ip) with following command.
1. Get Internal IP Address(es) on Linux Shell / Command Line
1.1 Get Single IP Address by Interface
Returns plain IP address./sbin/ifconfig $1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}' ## Example usage ## /sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}' 10.20.10.1 |
function int-ip { /sbin/ifconfig $1 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'; } ## Example usage ## int-ip eth0 10.20.10.1 |
1.2 Get Every Interfaces IP Address
Returns every interface and IP address pairs./sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }' ## Example output ## eth0: 10.20.10.1 eth1: 10.20.1.168 lo: 127.0.0.1 |
function int-ips { /sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }'; } ## Example usage ## int-ips eth0: 10.20.10.1 eth1: 10.20.1.168 lo: 127.0.0.1 |
2. Get External IP Address on Linux Shell / Command Line
I use here whatismyip.org service.2.1 Get External IP Address Using Lynx
Returns plain IP address.lynx --dump http://ipecho.net/plain ## Example output ## 80.10.10.80 |
Create simple bash function (example ext-ip) with following command.
function ext-ip () { lynx --dump http://ipecho.net/plain; } ## Example usage ## ext-ip 80.10.10.80 |
2.2 Get External IP Address Using Curl
Returns plain IP address.curl http://ipecho.net/plain; echo ## Example output ## 80.10.10.80 |
function ext-ip () { curl http://ipecho.net/plain; echo; } ## Example usage ## ext-ip 80.10.10.80 |
相关文章推荐
- linux 得到内网外网ip
- linux内网机器如何查看本地外网ip
- linux内网机器如何查看本地外网ip
- 动态IP或无公网IP时外网SSH访问内网linux
- linux下如何得到外网分配的ip
- linux设置好IP后,可以访问内网,不能访问外网
- 如何获取本机内网和外网IP(windows+linux)
- 根据Request获取客户端IP 内网IP及外网IP
- linux/unix/windows环境查看本机的外网内网地址方法
- 详解几种Linux 查询外网出口IP命令的方法
- Linux本地网络脚本配置(内网与外网)
- 通过ip区分内网和外网
- linux技巧--查看外网ip
- 内网通过外网IP访问内网服务器?
- linux: centos设置ip以及连接外网的方法
- 用Linux命令行获取本机外网IP地址
- 动态IP或无公网IP时外网访问内网固定端口管家婆等应用
- 动态IP或无公网IP时外网访问内网MYSQL数据库