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.