A summary of Python's method of acquiring IP address in extranet

Source: Internet
Author: User
Tags get ip

This example summarizes Python's approach to acquiring an extranet IP address. Share to everyone for your reference. Specifically as follows:

First, use the script engine library to obtain directly

?

1 2 3 4 5 6 7 Import console; Import web.script import inet.http; var JSVM = web.script ("JavaScript") Jsvm.addcode (Inet.http (). Get ("Http://fw.qq.com/ipaddress") var ipaddr = JSVM.CODEOBJECT.IPDATA[0]; Console.log ("Your Extranet IP address:", ipaddr)

Second, HTTP library, pattern matching acquisition

?

1 2 3 4 5 6 7 8 9 10 Import Inet.http; GetIP = function () {var http = inet.http () http.flags = 0x80000000/*_internet_flag_reload Force file to download from server is not cached * * | 0x4000000/*_i nternet_flag_dont_cache* do not cache data/var str = http.get ("http://fw.qq.com/ipaddress") return Str?string.match (str, ' "(. +?)" ")} Io.open () Io.print (GetIP ())

Third, Whttp library, pattern matching acquisition

?

1 2 3 4 5 6 7 8 9 10 11 Get IP import inet.whttp; GetIP = function () {var whttp = inet.whttp () var str = whttp.get ("Http://www.ip138.com/ip2city.asp? R= "+tonumber (Time.now ())) Whttp.close () return Str?string.match (str, [(. *)]");} Io.open () Io.print (GetIP ())

Four, API method

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21-22 Io.open (); var Iphlpapi = Raw.loaddll ("Iphlpapi.") DLL ") var getipaddrtable = Iphlpapi.api (" getipaddrtable "," Int (struct &pipaddrtable,int &pdwsize,int) ") Ipinfo = class {int dwaddr; int dwindex; int dwmask; int dwbcastaddr; int dwreasmsize; word unused1; Word unused2} var P Mib_ipaddrtable = class {int dentrys; struct mipinfo[255] = {. Ipinfo ()}; var ipstruct = pmib_ipaddrtable (); var re, ipstruct, ret = getipaddrtable (ipstruct, 0, 1); var re, ipstruct, ret = getipaddrtable (ipstruct, Re, 0); var ipdata = ipstruct.mipinfo[ipstruct.dentrys-1].dwaddr; var ip = raw.convert ({int n = ipdata}, {BYTE data[4]}); Io.print (String.Format ("%d.%d.%d.%d", ip.data[1), ip.data[2], ip.data[3], ip.data[4));

I hope this article will help you with your Python programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.