Python đặt địa chỉ IP

Lý do thiết lập bộ định tuyến ADSL làm bộ chuyển mạch là để tăng cường tín hiệu WiFi tại bàn làm việc của tôi. Tuy nhiên, đôi khi tôi cần chuyển về giao diện WiFi iiscwlan khi di chuyển máy tính xách tay của mình

Đặt IP động

Đầu tiên, bộ điều hợp WiFi máy tính xách tay của tôi đã kết nối với wololo WAP của modem ADSL + bộ định tuyến

Ngắt kết nối khỏi WAP wololo

Cho phép giao diện

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
0 bật DHCP

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
1

Kết nối với WAP iiscwlan. Máy chủ DHCP tại

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
3 và
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
4 tự động gán Địa chỉ IP
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
0 cho giao diện WiFi có chỉ số
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
1 và bí danh
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
0

Lưu ý các máy chủ DNS được đặt thành

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
3 và
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
4. Tuy nhiên, đôi khi những thứ này không được đặt và cần được tải xuống từ các máy chủ DHCP

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
5

Bằng cách này, IP được đặt động. Đó là nó

Đặt IP tĩnh

Chạy powershell với tư cách Quản trị viên và kiểm tra chỉ mục giao diện cho giao diện WiFi. Giao diện có chỉ số

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
1 với bí danh
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
0. Nó được kết nối với WAP iiscwlan bằng địa chỉ IP
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
0

iiscwlan0

Ngắt kết nối khỏi WAP iiscwlan

Để kết nối với WAP wololo, chúng tôi cần biết địa chỉ mạng của nó. Chúng tôi biết nó thuộc về địa chỉ mạng iiscwlan3 với các địa chỉ IP khả dụng bắt đầu từ iiscwlan4 vì địa chỉ bộ định tuyến là

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
4. Hãy để chúng tôi đặt địa chỉ IP của giao diện
#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
0 thuộc phạm vi này. Hãy để chúng tôi dành iiscwlan7 cho giao diện ethernet của máy tính để bàn

iiscwlan8

Điều này bật lên một iiscwlan9 nói rằng Cổng mặc định đã tồn tại. Hãy để chúng tôi xóa tùy chọn Cổng mặc định và thử lại

wololo0

Một lần nữa bật lên một iiscwlan9

Để giải quyết vấn đề này, trước tiên hãy kết nối với WAP wololo, sau đó thực hiện lệnh mà không có cổng mặc định vì WAP iiscwlan trước đó đã có cùng một cổng mặc định

#!python
'''Script to set Dynamic IP to the WiFi adaptor of laptop
 so that it auto configure to have an IP address that
 belongs to the same network address as that of the iiscwlan WAP.'''

import subprocess
dhcpCommand = '''netsh interface ip set address "WiFi" dhcp'''
command = dhcpCommand.split[]
subprocess.run[command]
4

Chúng ta cần đặt máy chủ DNS

wololo5

Bằng cách này, IP được đặt tĩnh. Đó là nó

Đặt địa chỉ IP động bằng cách sử dụng tập lệnh Python

Nhập các lệnh này rất hữu ích. Tuy nhiên, do yêu cầu về trình tự chính xác cũng như yêu cầu về độ chính xác, tốt hơn là nên có một tập lệnh riêng cho cài đặt địa chỉ IP tĩnh hoặc động

Nhờ khả năng viết kịch bản của Python để xử lý việc thực thi lệnh hệ thống, chúng tôi sử dụng mô-đun wololo6 cho tác vụ

Tôi có thể gán địa chỉ IP không?

Nhấp chuột phải vào bộ điều hợp mạng mà bạn muốn gán địa chỉ IP và nhấp vào Thuộc tính. Đánh dấu Giao thức Internet Phiên bản 4 [TCP/IPv4] sau đó nhấp vào nút Thuộc tính. Bây giờ hãy thay đổi IP, Mặt nạ mạng con, Cổng mặc định và Địa chỉ máy chủ DNS. Khi bạn hoàn tất, hãy nhấp vào OK

Làm cách nào để python xác minh địa chỉ IP?

Khoa học dữ liệu thực tế sử dụng Python .
Xác định một phương thức checkv4[x], điều này sẽ kiểm tra xem x có nằm trong phạm vi từ 0 đến 255 hay không, sau đó là true, nếu không thì là false
Định nghĩa một phương thức checkv6[x], phương thức này sẽ hoạt động như sau -.
Từ phương pháp chính
Nếu đầu vào có ba dấu chấm và với mỗi phần tôi kiểm tra v4[i] là đúng, thì hãy trả về “IPv4”

Chủ Đề