|
@@ -1,22 +1,65 @@
|
|
|
import requests
|
|
|
+import subprocess
|
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
from django.http import HttpResponse
|
|
|
+from django.shortcuts import render
|
|
|
|
|
|
|
|
|
-def base(request):
|
|
|
+def base(request) -> HttpResponse:
|
|
|
return HttpResponse("<h1> Base views: Response - 200_OK </h1>")
|
|
|
|
|
|
|
|
|
-def base_info(request):
|
|
|
+def base_info(request) -> HttpResponse:
|
|
|
return HttpResponse("<h1> Info views: Response - 200_OK<br>Mironov Misha</h1>")
|
|
|
|
|
|
|
|
|
-def status_output(request):
|
|
|
+def status_output(request) -> HttpResponse:
|
|
|
+ user_agent = request.META["HTTP_USER_AGENT"]
|
|
|
response = requests.get(url='https://2ip.ru/')
|
|
|
bs = BeautifulSoup(response.text, "lxml")
|
|
|
ip = bs.find('div', 'ip')
|
|
|
|
|
|
return HttpResponse(
|
|
|
- f"<h1> IP: {ip.text} </h1><br><h3>Для безопасности изменены последние 2 числа (после точек)</h3>"
|
|
|
+ f"<h1> IP: {ip.text} </h1><br><h1> IP: {user_agent} </h1><br><h3>Для безопасности изменены последние 2 "
|
|
|
+ f"числа (после точек)</h3> "
|
|
|
)
|
|
|
+
|
|
|
+
|
|
|
+def get_status_ipv4(request) -> HttpResponse:
|
|
|
+ get_info = subprocess.check_output(
|
|
|
+ ["powershell.exe", "Get-NetIPConfiguration -InterfaceAlias Ethernet -Detailed"], shell=True
|
|
|
+ )
|
|
|
+ decoded = get_info.decode('ISO-8859-1').replace('\r', '')
|
|
|
+
|
|
|
+ return HttpResponse(
|
|
|
+ f'<h3 style="max-width: 320px;">{decoded}</h3>'
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def post_status_ipv4(request):
|
|
|
+ if request.method == 'POST':
|
|
|
+ ip_addr = request.POST.get('ip_addr')
|
|
|
+ ip_mask = request.POST.get('ip_mask')
|
|
|
+ ip_dns = request.POST.get('ip_dns')
|
|
|
+ # -InterfaceAlias Ethernet - Это моя локальная, личная настройка. Её следует менять для других!
|
|
|
+ if ip_addr:
|
|
|
+ subprocess.call(
|
|
|
+ ["powershell.exe", f"Set-NetIPAddress -InterfaceAlias Ethernet -IPAddress {ip_addr}"],
|
|
|
+ shell=True
|
|
|
+ )
|
|
|
+ if ip_mask:
|
|
|
+ subprocess.call(
|
|
|
+ ["powershell.exe", f"Set-NetIPAddress -InterfaceAlias Ethernet -PrefixLength {ip_mask}"],
|
|
|
+ shell=True
|
|
|
+ )
|
|
|
+ if ip_dns:
|
|
|
+ subprocess.call(
|
|
|
+ ["powershell.exe", f"Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses {ip_dns}"],
|
|
|
+ shell=True
|
|
|
+ )
|
|
|
+ return HttpResponse(
|
|
|
+ "<h1>Good news! Check your ip setting! ( win + R -> ncpa.cpl)</h1>"
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ return render(request, 'post_form.html')
|