import socket
from tkinter import *
class ipAddress:
def __init__(self):
window = Tk()
window.title("ipAddress")
frame = Frame(window)
frame.pack()
Label(frame, text="域名:").grid(row=1, column=1)
self.ipName = StringVar()
Entry(frame, textvariable=self.ipName).grid(row=1, column=2)
Button(frame, text="查找", command=self.getIpAddress).grid(row=1, column=3)
self.toString = StringVar()
label = Label(window, textvariable=self.toString, anchor=NW, font=("consolas", 15), bg="white", height=15,
width=60)
label.pack()
window.mainloop()
def getIpAddress(self):
try:
ipAddress = socket.gethostbyname(self.ipName.get())
self.toString.set(str(self.ipName.get()) + "的IP地址为:" + str(ipAddress))
except:
self.toString.set("请输入正确的域名!")
ipAddress()
暂无评论