함수 get eth0 ip()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:32 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
함수 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 }}