함수 get eth0 ip()

함수 get_eth0_ip()

1 Bash[ | ]

/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'
# 135.79.246.80

2 PHP[ | ]

$ip = exec('/sbin/ifconfig eth0 | grep "inet addr:" | cut -d: -f2 | awk "{print \$1}"');
echo $ip;
# 135.79.246.80

3 Python[ | ]

import subprocess
ip = subprocess.Popen('/sbin/ifconfig eth0 | grep "inet addr:" | cut -d: -f2 | awk "{print \$1}"', shell=True, stdout=subprocess.PIPE).stdout.read().strip()
print( ip )
import socket, fcntl, struct
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ip = socket.inet_ntoa(fcntl.ioctl(s.fileno(),0x8915,struct.pack('256s','eth0'))[20:24])
print( ip )

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}