ip address check python module written anti-

2010-02-02  来源:本站原创  分类:Python  人气:262 

Search by IP address anti-attribution to the python module business logic from the other C + + module development has been completed.

#include <Python.h>
#include "iplookup.h"

static  il_db_t _g_db;
ipitem  ip_lookup(const char *query)
{
        const char *encoding = "UTF-8";
        data_type type = text;
        ipitem iphm;
        il_iplookup(query, iphm, _g_db, type, encoding);
        return iphm;
}

static PyObject * wrap_ip_lookup(PyObject *self, PyObject *args)
{
    const char * command;

    if (!PyArg_ParseTuple(args, "s", &command))// This is the Python variable  args To c variables  command
        return NULL;
    ipitem  iphm = ip_lookup(command);// Call the c function  

    return Py_BuildValue("(sssssss)",iphm.country ,iphm.province,iphm.city  ,iphm.district,iphm.isp     , iphm.type    , iphm.desc);

// The return value of the c  n Converted to a Python object
}

 // 3  The list of methods
static PyMethodDef IpLocateMethods[] = {
  {"ip_lookup", wrap_ip_lookup, METH_VARARGS, "locate ip address."},
  {NULL, NULL, 0, NULL}
 };

PyMODINIT_FUNC initiplocate(void)
{
    PyObject *m = Py_InitModule("iplocate", IpLocateMethods);
        const char* db_file = "/opt/iplookup/share/ip.db";
        _g_db = il_open(db_file);
    if (m == NULL) return;
}

Compiler installation:
g + +-pthread-fno-strict-aliasing-DNDEBUG-g-fwrapv-O2-Wall-fPIC-I. -I/opt
/ Python2.6/include/python2.6-c iplocate.cpp-o iplocate.o

g + +-Xlinker-export-dynamic-pthread-shared-Wl,-O1-Wl libiplookup_la-ip.o
libiplookup_la-iplookup.o libiplookup_la-iconv_ext.o iplocate.o-o iplocate.so
-I / opt/python2.6/include/python2.6-I / usr / include /

Move the generated module:
/ Opt/python2.6/lib/python2.6/lib-dynload /

相关文章
  • ip address check python module written anti- 2010-02-02

    Search by IP address anti-attribution to the python module business logic from the other C + + module development has been completed. #include <Python.h> #include "iplookup.h" static il_db_t _g_db; ipitem ip_lookup(const char *query) { con

  • Newbie: According to the ip address check switch port 2010-04-07

    interface map show cam arp cdp detail mac-address-table In the middle of a Cisco switched network, known IP address of a machine, how to find out which station it is connected to which port on the switch then? The most convenient way to make use Cisc

  • THinkPHP to get client IP and check address 2010-05-21

    Unfinished TP1.5 to get the client IP address of the system of public function is: function get_client_ip (). Return value is the IP address. Check IP address of the host country and the region class file is IpLocation.class.php, located ThinkPHP \ L

  • Check IP address is legitimate, and check the IP address type 2010-10-25

    <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN"> <HTML> <HEAD> <TITLE> New Document </ TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author&q

  • Access to the machine with python ip address 2010-02-02

    #!/usr/bin/python #coding=utf-8 import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifnam

  • How to check the current network of other computers ip address 2011-06-17

    Such as machine called testPC You can run from cmd and then ping testPC, you can get ip address. Alas, the problems encountered in the work today, was despised. . .

  • perl ip address get mac address under the 2011-04-14

    Sometimes need a host to get its mac address ip address, this can be achieved, but this must be the same ip address ip address within the Ethernet. In the perl module Net:: ARP can achieve this function. But it's arp_lookup function only from the loc

  • java to resolve host names for ip address 2010-04-02

    Today, when reading a book on the hands-on examples of knock program written by java can be resolved by entering the host name to its ip address import java.net.*; /** * Resolve the host name to obtain an IP address */ public class GetIp { public sta

  • ctypes python module applications in Chinese help documentation 2010-02-04

    Translator: butland, translated in 2010.1.2 - 2010.1.3, personal blog: http://butlandblog.appspot.com/ Content: . Load the dynamic link library . Dll is loaded from the reference function . Call the function 1 . The basic data types . Call the functi

  • linux network card bind multiple IP address (change) 2010-06-17

    Bind a number of IP card linux network device configuration files are located in / etc / sysconfig / network-scripts which, For the first Ethernet network device, configure the file name is generally ifcfg-eth0. If you need more than the first networ

  • IP Address Classification 2010-06-22

    The basic IP address is divided into 8-bit one unit (known as 8-bit group) of 32-bit binary number. Binary and decimal everybody understood it. In order to facilitate people's use of the machine-friendly binary address into the more familiar decimal

  • One IP protocol Xiangjie: IP address of the knowledge 2010-07-21

    IP is the TCP / IP protocol suite lies at the core of the agreement. All of the TCP, UDP, ICMP and IGMP for IP packet data format for transmission. IP provides unreliable, connectionless datagram delivery service. Not reliable (unreliable) means that

  • Comparison of IP address problem 2010-08-19

    Comparison between the IP address of record about. / / Check whether the IP address of an ip section in between function checkIPAddress (ipAddress, apnIpHigh, apnIpLow) ( if (ipAddress> = apnIpLow & & ipAddress <= apnIpHigh) ( return true; )

  • java network programming under the domain name for ip address, URL 2010-08-19

    Domain Name, the domain can be converted to ip address InetAddress can also use the getAddress () to get the IP address, but its return value is a 4 byte array. Thus, although getAddress () in the IP aspects of access is useful but not suitable for e

  • Development Notes: Python Module in 2010-09-16

    Python Module of the more important concepts. Common situation is a pre-written. Py file in another file, need to import, it will be written in advance. Py files are copied to the current directory, or add in sys.path prior written. Py file where the

  • integer ip address switch 2010-11-04

    What / Where / Why: General forum bbs we often see some titles on the. In serious cases, moderators will block the user's area of ip, so can not log in, will see some bbs's signature on the current user location display your ip and regional informati

  • ID. IP address. Phone number query entry 2010-11-26

    The three addresses, the return is xml, xml you only need to read about it. 1: Query ID http://www.youdao.com/smartresult-xml/search.s?type=id&q=140729198910260038 2: query IP address http://www.youdao.com/smartresult-xml/search.s?type=ip&q=222.37

  • The python module uuid 2010-12-14

    The python module uuid uuid is a unique identifier, for identification purposes in many areas. python's uuid module is used to generate it. Gossip did not say, python uuid generation method of providing a total of four kinds, namely: 1. From the hard

  • Access to external network IP address of the machine (External IP Address) 2010-12-15

    import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Gets the native outside the n

  • ESX Server IP address change 2010-12-25

    ESX Server IP address change ESX Server address today to modify a number of problems when, briefly describe the correct operation: Note: The following procedure is best in front of the machine or through the ILO interface operation, if the SSH remote