Question: Python program in pycharm. Build a GUI. I tried to build a GUI using Tkinter in python. I have done some part but I am

Python program in pycharm. Build a GUI.

I tried to build a GUI using Tkinter in python. I have done some part but I am still not able to print the output using a loop. I want to print all open ports in this program. I wrote some code but it is still not printing output here. Please, someone, help me to print this program. The sample inputs are:

please enter ip: 192.168.10.3

please enter portStart: 1

please enter portEnd: 100

this part is working but haveing problem to print out the output which is open ports.

import socket

from tkinter import *

root = Tk()

root.geometry("400x500")

iplabel1 = Label(root, text= "please enter ip", bg = "white")

iplabel1.grid(row=1,column=1, sticky=W)

ip = StringVar()

ipEntry= Entry(root,textvariable=ip)

ipEntry.grid(row=2,column=1)

startlabel = Label(root, text= "please enter portStart", bg = "white")

startlabel.grid(row=4,column=1, sticky=W)

portStart = StringVar()

StartEntry= Entry(root,textvariable=portStart)

StartEntry.grid(row=5,column=1)

endlabel = Label(root, text= "please enter portEnd", bg = "white")

endlabel.grid(row=7,column=1, sticky=W)

portEnd = StringVar()

EndEntry= Entry(root,textvariable=portEnd)

EndEntry.grid(row=8,column=1)

def printports ():

string1 = ''

ipvalue = ip.get()

startvalue = portStart.get()

endvalue = portEnd.get()

for port in range (int(startvalue), int(endvalue)):

value = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

connected = value.connect_ex((ipvalue,port))

if connected ==0:

#print("{} port is open".format(port))

string1 += "port is open "

string1 += str(port)

string1 += "/n"

printlabel = Label(root,text=string1)

printlabel.grid(row=12, column=1)

# print(string1)

b1=Button(root, text="Scan", command= lambda: printports())

b1.grid(row=10, column=1)

mainloop()

# this code is working only print the ports when not using the tkinter.

# ip = input("Input IP ")

# portStart = input("Begining port ")

# portEnd = input("End port")

#

# for port in range (int(portStart), int(portEnd)):

# value = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

# connected = value.connect_ex((ip,port))

# if connected ==0:

# print("{} port is open".format(port))

#

# print("complete")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!