🔅 Scan for open ports
from socket import *
import time
startTime = time.time()
if __name__ == '__main__':
target = input('Enter the host to be scanned: ')
t_IP = gethostbyname(target)
print ('Starting scan on host: ', t_IP)
for i in range(1, 10000):
s = socket(AF_INET, SOCK_STREAM)
conn = s.connect_ex((t_IP, i))
if(conn == 0) :
print ('Port %d: OPEN' % (i,))
s.close()
print('Time taken:', time.time() - startTime)
🔥23👍17❤12😁1
🔅 Compress Images
from PIL import Image
# https://t.me/LearnPython3
in_img = 'input.png'
out_img = 'compressed.png'
# Open the image
with Image.open(in_img) as img:
# Save the compressed image
img.save(out_img, 'PNG', quality=80)
print(f"Image compressed successfully!")
❤24👍12🔥8
🔅 Extract the colors and their codes from an image
from PIL import Image
from collections import Counter
# https://t.me/LearnPython3
# Open the image
image = Image.open('input.png')
# Convert the image to a list of RGB tuples
pixels = list(image.getdata())
# Use Counter to count the occurrences of each color
color_counts = Counter(pixels)
# Get the 6 most common colors
top_colors = color_counts.most_common(6)
# Print the extracted colors and their counts
for i, (color, count) in enumerate(top_colors):
color_block = "\033[48;2;{};{};{}m \033[0m".format(color[0], color[1], color[2])
print(f"Color {i + 1}: {color_block} RGB: {color} - Count: {count}")
👍27❤10🔥10👏1
🔅 Merge PDFs
@LearnPython3
pip install PyPDF2
from PyPDF2 import PdfFileMerger
# https://t.me/LearnPython3
# By appending in the end
def by_appending():
merger = PdfFileMerger()
# Either provide file stream
f1 = open("samplePdf1.pdf", "rb")
merger.append(f1)
# Or direct file path
merger.append("samplePdf2.pdf")
merger.write("mergedPdf.pdf")
# By inserting at after an specified page no.
def by_inserting():
merger = PdfFileMerger()
merger.append("samplePdf1.pdf")
merger.merge(0, "samplePdf2.pdf")
merger.write("mergedPdf1.pdf")
if __name__ == "__main__":
by_appending()
by_inserting()
@LearnPython3
👍39❤17🔥5👎2
🚀 Alright, let's talk about modules and packages in Python.
A module is like a file that contains Python code. It can have functions, classes, or variables. When you want to use something from a module, you import it using the
Now, a package is a way to organize related modules into a directory hierarchy. Think of it as a collection of modules bundled together. To make a directory a package, you just need to include a special file called
So, in simple terms, a module is a single file with Python code, and a package is a collection of modules organized in a directory. Modules are like building blocks, and packages are like containers holding those blocks. Easy, isn't it? 🧩
A module is like a file that contains Python code. It can have functions, classes, or variables. When you want to use something from a module, you import it using the
import
keyword. Simple, right? 🤓Now, a package is a way to organize related modules into a directory hierarchy. Think of it as a collection of modules bundled together. To make a directory a package, you just need to include a special file called
__init__.py
in it.So, in simple terms, a module is a single file with Python code, and a package is a collection of modules organized in a directory. Modules are like building blocks, and packages are like containers holding those blocks. Easy, isn't it? 🧩
👏47❤23👍18🔥10
🔰 Learn Python 3.9 | Start your Programming Career in 4 Hours
🌟 4.0 - 36 votes 💰 Original Price: $29.99
Taught By: CyberSkill Academy
Download Full Course: https://t.me/LearnPython3/894
Download All Courses: https://t.me/zero_to_mastery
🌟 4.0 - 36 votes 💰 Original Price: $29.99
Learn Python in just 4 hours! Master the fundamentals, build practical skills, and start coding with this course
Taught By: CyberSkill Academy
Download Full Course: https://t.me/LearnPython3/894
Download All Courses: https://t.me/zero_to_mastery
👍46❤12👏6🤗5
1. Introduction.zip
98.2 MB
1. Introduction
2. Strings in Python.zip
187.2 MB
2. Strings in Python
3. Numbers in Python.zip
42.4 MB
3. Numbers in Python
4. Lists in Python.zip
164.5 MB
4. Lists in Python
5. Loops in Python.zip
201.6 MB
5. Loops in Python
6. If, Else, Else If.zip
93.7 MB
6. If, Else, Else If
7. Functions in Python.zip
156.6 MB
7. Functions in Python
8. OOP - Classes in Python.zip
137.9 MB
8. OOP - Classes in Python
👍117❤49🥰7👏3