💚 سلام دوستان عزیزم 💚

🛑 برای یک برنامه بسیار ارزشمند و هیجان‌انگیز به زبان پایتون آماده شوید!

فلسفه برنامه شماره سی و سه (۳۳):

زمانی که ما از طریق Wireless LAN Adapter دستگاه‌مان (لپتاب‌مان)، یک دستگاه WIFI Router، در اطراف‌مان را پیدا (شناسایی) کرده و با یک گذرواژه به آن متصل می‌شویم، اطلاعات مربوط به آن WIFI Router، در قالب یک فایل ‌Profile، بر روی دستگاه ما ذخیره می‌گردد، و گذرواژه‌ای که در زمان اتصال، ثبت کرده‌ایم، (متاسفانه) به صورت Plain Text، در همان فایل ذخیره می‌گردد!

حال می‌خواهیم برنامه‌ای بنویسیم، که فهرست تمام اسامی WIFI Profile های ثبت شده بر روی دستگاه ما را چاپ نموده و در مقابل هر یک از آن‌ها، گذرواژه مربوطه (ذخیره شده) را نمایش دهد!

نکته: همانند پروژه‌های قبل نیز، می‌خواهیم این کار را به صورت مرحله به مرحله (در چهار مرحله) انجام داده و در نهایت، به یک کد کامل، با رعایت تمام اصول Clean Code و Best Practice دست پیدا کنیم.

#SourceCode #SourceCode10033 #Practical #EthicalHacking
ادمین:
@Dariush_Tasdighi
کانال اصلی:
@IranianExperts
کانال پایتون:
@DT_PYTHON_LEARNING
.
👍43
📌 عنوان برنامه: برنامه‌ای بنویسید که فهرست تمام WIFI Profile های ثبت شده بر روی دستگاه‌تان را چاپ نموده و در مقابل هر یک از آن‌ها، گذرواژه مربوطه (ذخیره شده) را نمایش دهد؟

مرحله اول

- قدم اول:
در محیط Windows PowerShell دستور ذیل را اجرا کرده و نتیجه آن‌را مشاهده می‌کنیم:

# ********************
netsh wlan show profiles
# ********************

- قدم دوم: حال این دستور را توسط زبان برنامه‌نویسی پایتون اجرا می‌کنیم و نتیجه اجرای این دستور را در متغیری به نام profiles_string ذخیره می‌کنیم:

# ********************
import subprocess

command = "netsh wlan show profiles"
profiles_string = subprocess.getoutput(cmd=command)
print(profiles_string)
# ********************

- قدم سوم: با استفاده از دستورات و توابع مربوط به string، سعی می‌کنیم که از این متن، یک لیست ایجاد کنیم که آیتم‌های آن، اسامی WIFI Network ها باشد:

# ********************
import subprocess

command = "netsh wlan show profiles"
profiles_string = subprocess.getoutput(cmd=command)

index = profiles_string.find("User profiles")

profiles_string = profiles_string[index:]
profiles_string = profiles_string.replace("User profiles", "")
profiles_string = profiles_string.replace("-------------", "")
profiles_string = profiles_string.replace("\r", "")

profiles_lines = profiles_string.split(sep="\n")

wifi_names = []
for line in profiles_lines:
if line != "":
parts = line.split(sep=":")
wifi_name = parts[1].strip()
wifi_names.append(wifi_name)

wifi_names.sort()

for wifi_name in wifi_names:
print(f"[{wifi_name}]")
# ********************

#SourceCode #SourceCode10033 #Practical #EthicalHacking
ادمین:
@Dariush_Tasdighi
کانال اصلی:
@IranianExperts
کانال پایتون:
@DT_PYTHON_LEARNING
.
3👍2
📌 عنوان برنامه: برنامه‌ای بنویسید که فهرست تمام WIFI Profile های ثبت شده بر روی دستگاه‌تان را چاپ نموده و در مقابل هر یک از آن‌ها، گذرواژه مربوطه (ذخیره شده) را نمایش دهد؟

مرحله دوم

- فرض کنید که نام یکی از WIFI های شما، MobinNet110 باشد.

- قدم اول: در محیط Windows PowerShell دستور ذیل را اجرا کرده و نتیجه آن‌را مشاهده می‌کنیم:

# ********************
netsh wlan show profile name="MobinNet110" key=clear
# ********************

- قدم دوم: حال این دستور را توسط زبان برنامه‌نویسی پایتون اجرا می‌کنیم و نتیجه اجرای این دستور را در متغیری به نام profile_string ذخیره می‌کنیم:

# ********************
import subprocess

wifi_name = "MobinNet110"

command = f'netsh wlan show profile name="{wifi_name}" key=clear'
profile_string = subprocess.getoutput(cmd=command)
print(profile_string)
# ********************

- قدم سوم: با استفاده از دستورات و توابع مربوط به string، سعی می‌کنیم که از این متن، گذرواژه (password) موجود در متن را استخراج کرده و آن‌را نمایش می‌دهیم:

# ********************
import subprocess

wifi_name = "MobinNet110"

command = f'netsh wlan show profile name="{wifi_name}" key=clear'
profile_string = subprocess.getoutput(cmd=command)

index_1 = profile_string.find("Key Content")
index_2 = profile_string.find("Cost settings")

profile_string = profile_string[index_1:index_2]
profile_string = profile_string.replace(":", "")
profile_string = profile_string.replace("Key Content", "")

password = profile_string.strip()
print(f"[{password}]")
# ********************

#SourceCode #SourceCode10033 #Practical #EthicalHacking
ادمین:
@Dariush_Tasdighi
کانال اصلی:
@IranianExperts
کانال پایتون:
@DT_PYTHON_LEARNING
.
2👍2
📌 عنوان برنامه: برنامه‌ای بنویسید که فهرست تمام WIFI Profile های ثبت شده بر روی دستگاه‌تان را چاپ نموده و در مقابل هر یک از آن‌ها، گذرواژه مربوطه (ذخیره شده) را نمایش دهد؟

مرحله سوم

- حال کافی است که کدهای مرحله یک و مرحله دو را در هم ادغام نماییم!

# ********************
import subprocess

command = "netsh wlan show profiles"
profiles_string = subprocess.getoutput(cmd=command)

index = profiles_string.find("User profiles")

profiles_string = profiles_string[index:]
profiles_string = profiles_string.replace("User profiles", "")
profiles_string = profiles_string.replace("-------------", "")
profiles_string = profiles_string.replace("\r", "")

profiles_lines = profiles_string.split(sep="\n")

wifi_names = []
for line in profiles_lines:
if line != "":
parts = line.split(sep=":")
wifi_name = parts[1].strip()
wifi_names.append(wifi_name)

wifi_names.sort()

for wifi_name in wifi_names:
command = f'netsh wlan show profile name="{wifi_name}" key=clear'
profile_string = subprocess.getoutput(cmd=command)

index_1 = profile_string.find("Key Content")
index_2 = profile_string.find("Cost settings")

profile_string = profile_string[index_1:index_2]
profile_string = profile_string.replace(":", "")
profile_string = profile_string.replace("Key Content", "")

password = profile_string.strip()
print(f"[{wifi_name}]: [{password}]")
# ********************

نکته: همان‌طور که ملاحظه می‌کنید، برنامه به زیبایی کار می‌کند، ولی خروجی نتایج، از نظر ظاهری و قیافه چندان جذابیت ندارد، لذا در مرحله چهارم (مرحله آخر) یک سری تکنیک‌های حرفه‌ای به این کد اضافه می‌کنیم تا نتایج مورد قبول و پسند ما قرار گیرد!

#SourceCode #SourceCode10033 #Practical #EthicalHacking
ادمین:
@Dariush_Tasdighi
کانال اصلی:
@IranianExperts
کانال پایتون:
@DT_PYTHON_LEARNING
.
3👍1
📌 عنوان برنامه: برنامه‌ای بنویسید که فهرست تمام WIFI Profile های ثبت شده بر روی دستگاه‌تان را چاپ نموده و در مقابل هر یک از آن‌ها، گذرواژه مربوطه (ذخیره شده) را نمایش دهد؟

مرحله چهارم (پایانی)

🛑 یک برنامه کاربردی و هیجان‌انگیز با کلی تکنیک‌های حرفه‌ای برنامه‌نویسی!

# ********************
import os, subprocess

os.system(command="cls")

command = "netsh wlan show profiles"
profiles_string = subprocess.getoutput(cmd=command)

index = profiles_string.find("User profiles")

profiles_string = profiles_string[index:]
profiles_string = profiles_string.replace("User profiles", "")
profiles_string = profiles_string.replace("-------------", "")
profiles_string = profiles_string.replace("\r", "")

profiles_lines = profiles_string.split(sep="\n")

wifi_names = []
for line in profiles_lines:
if line != "":
parts = line.split(sep=":")
wifi_name = parts[1].strip()
wifi_names.append(wifi_name)

wifi_names.sort()

for index, wifi_name in enumerate(wifi_names):
command = f'netsh wlan show profile name="{wifi_name}" key=clear'
profile_string = subprocess.getoutput(cmd=command)

index_1 = profile_string.find("Key Content")
index_2 = profile_string.find("Cost settings")

profile_string = profile_string[index_1:index_2]
profile_string = profile_string.replace(":", "")
profile_string = profile_string.replace("Key Content", "")

password = profile_string.strip()
print(f"[{(index + 1):>2}] - [{wifi_name:<32}]: [{password}]")

print()
# ********************

#SourceCode #SourceCode10033 #Practical #EthicalHacking
ادمین:
@Dariush_Tasdighi
کانال اصلی:
@IranianExperts
کانال پایتون:
@DT_PYTHON_LEARNING
.
3👍2