0
이 python을 실행합니다. 모든 것이 좋습니다.왜 파이썬에서 configparser로 로컬 IP를 가져올 수 없습니까?
import socket
import sys
def get_local_ip(ifname):
print type(ifname)
import fcntl, struct
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
inet = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))
ret = socket.inet_ntoa(inet[20:24])
return ret
아웃
<type 'str'>
192.168.1.250
를 넣어하지만 여기
[config]
ethname = 'eth0'
socketConfig.conf 설정 파일 여기
내 구성 파일을 설정하려고 파이썬 코드
입니다 ,937,758,724,372,533,210는 밖으로 이러한 오류
<type 'str'>
Traceback (most recent call last):
File "socketClient.py", line 28, in <module>
print get_local_ip(eth)
File "socketClient.py", line 23, in get_local_ip
inet = fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))
IOError: [Errno 19] No such device
이 사람이 무슨 일이 일어나고 있는지 알고 있나요
을 넣어? 고맙습니다.
'print eth'. 나는 그것이 당신이 생각하는 것이 아니라고 생각하고 있습니다. – Shadow
@Shadow 시도했습니다. display 'eth0' – user3751111
그러면 설정 파일의 따옴표를 지우는 것을 변경하십시오. 따옴표가 선택되어 전달 된 것처럼 보입니다. – Shadow