Created
November 29, 2025 12:08
-
-
Save ve3xone/7d3aa9eda21b35c62bd70f0865fc0bfb to your computer and use it in GitHub Desktop.
Простой скрипт чтоб выбить себе нужный ip на яндекс cloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from yandex.cloud.vpc.v1.address_service_pb2_grpc import AddressServiceStub | |
| from yandex.cloud.vpc.v1.address_service_pb2 import ( | |
| CreateAddressRequest, | |
| DeleteAddressRequest, | |
| ExternalIpv4AddressSpec, | |
| CreateAddressMetadata | |
| ) | |
| from yandex.cloud.vpc.v1.address_pb2 import Address | |
| import yandexcloud | |
| import traceback | |
| import ipaddress | |
| def is_in_84_201_176(ip_str: str) -> bool: | |
| """ | |
| Returns True if *ip_str* belongs to 84.201.176.*, | |
| otherwise returns False. | |
| """ | |
| try: | |
| ip = ipaddress.IPv4Address(ip_str) | |
| except ipaddress.AddressValueError: | |
| return False | |
| return ip in ipaddress.IPv4Network("84.201.176.0/20") | |
| # Initialize the SDK and service stub | |
| sdk = yandexcloud.SDK(token="") | |
| address_service = sdk.client(AddressServiceStub) | |
| while True: | |
| try: | |
| # Create an Address | |
| create_operation = address_service.Create( | |
| CreateAddressRequest( | |
| folder_id="b1gsitt2ns6gr8rv1b8s", | |
| external_ipv4_address_spec=ExternalIpv4AddressSpec( | |
| zone_id="ru-central1-a" | |
| ), | |
| ) | |
| ) | |
| # Wait for the create operation to complete | |
| create_operation_result = sdk.wait_operation_and_get_result( | |
| create_operation, | |
| response_type=Address, | |
| meta_type=CreateAddressMetadata | |
| ) | |
| # Extract the new address information | |
| new_address = create_operation_result.response | |
| print(f"Created Address ID: {new_address.id}") | |
| print(f"IP Address: {new_address.external_ipv4_address.address}") | |
| ip = new_address.external_ipv4_address.address | |
| if not is_in_84_201_176(ip): | |
| # Delete the Address | |
| delete_operation = address_service.Delete( | |
| DeleteAddressRequest( | |
| address_id=new_address.id | |
| ) | |
| ) | |
| print("Address deleted successfully") | |
| else: | |
| print("Йоу") | |
| exit(0) | |
| except Exception as e: | |
| print(e) | |
| traceback.print_exc(e) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment