日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python10行代码制作企业内网IP地址查询网站

發(fā)布時間:2024/3/24 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python10行代码制作企业内网IP地址查询网站 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

企業(yè)內(nèi)部您是否遇到過IP無法定位和查詢的情況,而網(wǎng)絡(luò)和運(yùn)維的部分平臺不便開放給其他用戶。所以本次搭建簡單的IP查詢網(wǎng)站給普通用戶使用,

環(huán)境: 1.mongodb(可使用其他數(shù)據(jù)庫),數(shù)據(jù)庫安裝可自行查詢其他網(wǎng)站 2.streamlit 實(shí)現(xiàn)簡單網(wǎng)站查詢IP地址歸屬,簡單方便。

streamlit安裝可以參考

代碼如下:

#coding:utf-8import streamlit as st import pymongo@st.cache # 開啟緩存,如果不緩存,每次刷新都要請求,緩存可以減少搜索時間 def mongodb():# build connectionconn = pymongo.MongoClient('192.168.100.100', 27017) # connect dataBasemydb = conn.cmdb_data# get collectionmyCollect = mydb.cmdb_dns_list# myCollect.insert_one(data_dict)# print(myCollect)return myCollectdb = mongodb() # a = db.find() # 查詢所有的數(shù)據(jù)庫,無法直接查看,使用for循環(huán)可以打印出來 # a = db.find_one({"IP":"192.168.1.1"}) # 查詢單條數(shù)據(jù) # print(a) # for i in a: # print(i)st.header("IP地址查詢")title = st.text_input('請輸入IP', '192.168.1.1') st.write('輸入的內(nèi)容為', db.find_one({"IP":title}))# df = a # st.dataframe(df)

展示結(jié)果:

代碼過于簡單,可能存在注入等漏洞情況(雖然已經(jīng)限制只查詢IP),建議生產(chǎn)環(huán)境需要對輸入的內(nèi)容進(jìn)行限制。避免出現(xiàn)被提權(quán)的情況,那就得不償失啦

問題:

安裝streamlit 可能遇到下列錯誤

解決方案:

1、升級setuptools pip3 install --upgrade setuptools2、升級pip工具 pip3 install --upgrade pip

再安裝streamlit 已經(jīng)成功

============================================================================

內(nèi)網(wǎng)搭建公網(wǎng)IP查詢頁面

#coding:utf-8import streamlit as st import requests@st.cache def ip(ipaddress):url = "http://ip-api.com/json/{ip}?lang=zh-CN".format(ip=ipaddress)res = requests.get(url).json()# return resif res["status"] == "success":return {"狀態(tài)": "成功" if res["status"] in "success" else "失敗","國家": res["country"],"國家代碼": res["countryCode"],"區(qū)域": res["region"],"省份": res["regionName"],"城市": res["city"],"郵政編碼": res["zip"],"經(jīng)度": res["lat"],"緯度": res["lon"],"時區(qū)": res["timezone"],"運(yùn)營商": res["isp"],"企業(yè)或組織":res["org"],"AS": res["as"],"查詢IP": res["query"]}else:return ["輸入錯誤,請輸入公網(wǎng)IP地址"] st.header("IP地址查詢")title = st.text_input('請輸入IP', '1.1.1.1') # st.write('輸入的內(nèi)容為', db.find_one({"IP":title})) st.write('輸入的內(nèi)容為', ip(title))

頁面展示

總結(jié)

以上是生活随笔為你收集整理的Python10行代码制作企业内网IP地址查询网站的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。