2015-02-08 81 views
0

我不想製作一個基於IP返回國家的函數。 我已經將IP轉換爲十進制值,所以mysql可以使「之間」。 以下是我的票價。查找值到數值之間的值

def get(): 
    con = pymysql.connect(host='localhost', port=3306, user='root', 
    passwd='******', db='IP') 
    ip_d = "16777221" 
    with con: 

     cur = con.cursor() 
     return cur.execute("SELECT Land FROM IPaddresses where ip_d 
     BETWEEN Start and End") 
get() 

開始和結束是一個國家的第一個ip和結束ip,也表示爲一個deciamal值。

回答

0

MySQL之間的解釋: http://www.tutorialspoint.com/mysql/mysql-between-clause.htm

你應該改變StartEnd一些數字參數:

startValue=111222333 
endValue=888999000 

return cur.execute("SELECT Land FROM IPaddresses where ip_d 
    BETWEEN {start} and {end}".format(start=startValue,end=EndValue)) 
+0

我需要掃描througe數據庫中,所以它findes所在國ip_d是開始之間結束 – 2015-02-08 19:33:04