50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import socket
|
|
|
|
import serial
|
|
import serial.tools.list_ports
|
|
from PyQt5.QtWidgets import QDialog, QApplication
|
|
from netUI import Ui_netUI
|
|
|
|
|
|
class UiNet(QDialog, Ui_netUI):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setupUi(self)
|
|
self.init()
|
|
|
|
def init(self):
|
|
self.get_all_local_ips()
|
|
|
|
# 加载本地网络地址
|
|
def get_all_local_ips(self):
|
|
ip_addresses = []
|
|
for interface in socket.getaddrinfo(socket.gethostname(), None):
|
|
address = interface[4][0]
|
|
if ':' not in address: # IPv6地址包含冒号
|
|
ip_addresses.append(address)
|
|
print(ip_addresses)
|
|
for ip in ip_addresses:
|
|
self.comboBox_localAddr.insertItem(0, ip)
|
|
self.comboBox_localAddr.setCurrentIndex(0)
|
|
|
|
def get_local_ip(self):
|
|
return self.comboBox_localAddr.currentText()
|
|
|
|
def set_local_ip(self, ip_str):
|
|
self.comboBox_localAddr.setCurrentText(ip_str)
|
|
|
|
def get_port(self):
|
|
return self.lineEdit_port.text()
|
|
|
|
def set_port(self, port_str):
|
|
self.lineEdit_port.setText(port_str)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
|
|
app = QApplication(sys.argv)
|
|
ui = UiNet()
|
|
ui.show()
|
|
sys.exit(app.exec_())
|