Comments (2)
@PengYunjing 感谢您的建议,针对获取ip方法click_get_ip()已修改为如下形式:
def click_get_ip(self):
"""
pushbutton_get_ip控件点击触发的槽
:return: None
"""
# 获取本机ip
self.lineEdit_ip_local.clear()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('8.8.8.8', 80))
my_addr = s.getsockname()[0]
self.lineEdit_ip_local.setText(str(my_addr))
except Exception as ret:
# 若无法连接互联网使用,会调用以下方法
# self.signal_write_msg.emit("无法获取ip,请连接网络!\n")
my_addr = socket.gethostbyname(socket.gethostname())
self.lineEdit_ip_local.setText(str(my_addr))
finally:
s.close()
from tcp_udp_web_tools-pyqt5.
@PengYunjing 刚刚的修改未考虑到macOS获取ip会报错这个问题,以下为最终代码:
def click_get_ip(self):
"""
pushbutton_get_ip控件点击触发的槽
:return: None
"""
# 获取本机ip
self.lineEdit_ip_local.clear()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('8.8.8.8', 80))
my_addr = s.getsockname()[0]
self.lineEdit_ip_local.setText(str(my_addr))
except Exception as ret:
# 若无法连接互联网使用,会调用以下方法
try:
my_addr = socket.gethostbyname(socket.gethostname())
self.lineEdit_ip_local.setText(str(my_addr))
except Exception as ret_e:
self.signal_write_msg.emit("无法获取ip,请连接网络!\n")
finally:
s.close()
from tcp_udp_web_tools-pyqt5.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tcp_udp_web_tools-pyqt5.