Script to change ip address on windows

You can use the Python WMI module to do this (install the PyWin32 extensions and the WMI module before running these scripts). Here is how to configure things to talk to the hardware device: import wmi # Obtain network adaptors configurations nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True) # First network adaptor nic = nic_configs[0] # IP address, subnetmask … Read more

What is IPV6 for localhost and 0.0.0.0?

As we all know that IPv4 address for localhost is 127.0.0.1 (loopback address). Actually, any IPv4 address in 127.0.0.0/8 is a loopback address. In IPv6, the direct analog of the loopback range is ::1/128. So ::1 (long form 0:0:0:0:0:0:0:1) is the one and only IPv6 loopback address. While the hostname localhost will normally resolve to … Read more

Force requests to use IPv4 / IPv6

I’ve found a minimalistic solution to force urrlib3 to use either ipv4 or ipv6. This method is used by urrlib3 for creating new connection both for Http and Https. You can specify in it any AF_FAMILY you want to use. import socket import requests.packages.urllib3.util.connection as urllib3_cn def allowed_gai_family(): “”” https://github.com/shazow/urllib3/blob/master/urllib3/util/connection.py “”” family = socket.AF_INET if … Read more

Get destination address of a received UDP packet

I’ve constructed an example that extracts the source, destination and interface addresses. For brevity, no error checking is provided. // sock is bound AF_INET socket, usually SOCK_DGRAM // include struct in_pktinfo in the message “ancilliary” control data setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)); // the control data is dumped here char cmbuf[0x100]; // the remote/source sockaddr … Read more

How to configure a static IP address, netmask, gateway programmatically on Android 3.x or 4.x

I realise that there is no API on 3.x or 4.x for those setting per SSID. Therefore, I checked out the source code and found out that the configuration of each SSID is stored in android.net.wifi.WifiConfiguration which is gotten from android.net.wifi.WifiManager. In the below code, IpAssignment is an Enum, either STAIC, DHCP or NONE. And … Read more

How to convert an IPv4 address into a integer in C#?

32-bit unsigned integers are IPv4 addresses. Meanwhile, the IPAddress.Address property, while deprecated, is an Int64 that returns the unsigned 32-bit value of the IPv4 address (the catch is, it’s in network byte order, so you need to swap it around). For example, my local google.com is at 64.233.187.99. That’s equivalent to: 64*2^24 + 233*2^16 + … Read more