根据基站位置区识别码(LCA)和小区识别(CI)获取经纬度

这篇具有很好参考价值的文章主要介绍了根据基站位置区识别码(LCA)和小区识别(CI)获取经纬度。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

需求

在网络攻击溯源时,需要对攻击者的位置进行定位。

已知参数

已知攻击者发送攻击报文的接入基站的位置区识别码(LCA)和小区识别(CI)码

目标

获取攻击者位置文章来源地址https://www.toymoban.com/news/detail-697514.html

技术路线

  • request 调用API查询经纬度位置
  • openpyxl 读取 excel 表格
  • sqlite3 读写数据库
  • json 数据解析

Python 代码

import requests
from openpyxl import load_workbook
import re
import os
import json
import sqlite3

# 传入一个列表,里面包含字典数据。
def writeDB(conn, cursor, lac, ci, mnc, real_data):
    errcode  = real_data['errcode']
    lat = real_data['lat']
    lon = real_data['lon']
    radius = real_data['radius']
    address = real_data['address']
    
    cursor.execute("INSERT INTO lac_ci_cache(errcode, mnc, lac, ci, lat, lon, radius, address) VALUES (?,?,?,?,?,?,?,?)",(errcode, mnc, lac, ci, lat, lon, radius, address))
    conn.commit()
    

def queryCache(cursor, lac, ci):
    cursor.execute("SELECT * FROM lac_ci_cache WHERE lac = ? AND ci = ?",(lac, ci))
    results = cursor.fetchall()
    
    # 获取查询结果的列名
    column_names = [desc[0] for desc in cursor.description]
    
    # 将查询结果转换为字典列表
    result_dict_list = []
    
    for row in results:
        row_dict = dict(zip(column_names, row))
        result_dict_list.append(row_dict)
        
    print(result_dict_list)
        
    return result_dict_list

def writeData(sheet, row, operator_code, content_str, status):
    
    print('content_str:' + str(content_str))
    print(type(content_str))
    dict_data = ["lat","lon","radius","address"]
    # 正常写入逻辑
    if(status == 0):
        real_data = json.loads(content_str)
        for number in range(4, 4 + len(dict_data)):
            sheet.cell(row = row, column = number, value = real_data[dict_data[number-4]])
        
        # 8 运营商
        operator_str = ""
        if(operator_code == 0):
            operator_str = "移动"
        elif(operator_code == 1):
            operator_str = "联通"
        else:
            operator_str = "未知"
        
        sheet.cell(row = row, column = 4 + len(dict_data), value = '移动')
    # 异常写入逻辑
    else:
        for number in range(4, 4 + len(dict_data) + 1):
            sheet.cell(row = row, column = number, value = 'N/A')
        

    
def saveData(wb, file_name):
    wb.save(file_name)
    wb.close()
        
# return sheet
def getSheet(file_name, sheet_name):
    # 获取当前目录
    current_directory = os.getcwd()
    # subdirectory = "xxx"
    # current_directory = os.path.join(current_directory, subdirectory)
    print(current_directory)
    # 读取Excel文件
    excel_file_path = file_name  # 替换为你的Excel文件路径
    wb = load_workbook(filename=excel_file_path)

    # 选择工作表
    sheet = wb[sheet_name]  # 替换为你的工作表名称
    return sheet,wb



# return json text of lac ci
def getLocation(mnc, lac, ci, output):

    # 访问地址
    url = "http://api.cellocation.com:84/cell/?mcc=460&mnc={}&lac={}&ci={}&output={}".format(mnc, lac, ci, output) 
    
    # 打印URL
    print(url)
    
    # 定义要设置的Cookie
    
    # 发送HTTP GET请求获取页面内容
    response = requests.get(url)
    
    if response.status_code == 200:
        # 使用response.text获取页面的文本内容
        page_content = response.text
        
        return page_content;
    else:
        return 'none'
    

if __name__ == "__main__":
    
    # 连接到 SQLite 数据库
    conn = sqlite3.connect('data.db')
    
    # 创建一个游标对象,用于执行 SQL 语句
    cursor = conn.cursor()
    
    # 创建表格
    cursor.execute('''CREATE TABLE IF NOT EXISTS lac_ci_cache (
                        id INTEGER PRIMARY KEY AUTOINCREMENT,
                        errcode INTEGER,
                        mnc INTEGER,
                        lac INTEGER,
                        ci INTEGER,
                        lat REAL,
                        lon REAL,
                        radius REAL,
                        address TEXT
                    )''')                   
                    
    # 1 获取表单信息openpyxl
    sheet, wb= getSheet('lacci_test.xlsx','lacci_test')
    
    # 添加标题
    dict_data = ["纬度","精度","半径","地址","运营商"]
    for number in range(4, 4+len(dict_data)): 
        sheet.cell(row = 1, column = number, value = dict_data[number-4])
        
    # 2 遍历查询
    row_index = 1;
    for row in sheet.iter_rows(min_row=2, max_row=201, min_col=1, max_col=2):
        
        row_index = row_index + 1;
        print('row_index' + str(row_index))
        # 获取单元格的值
        lac_value = row[0].value
        ci_value = row[1].value
        
        # 查询数据库是否已经存在
        cache_value = queryCache(cursor, lac_value, ci_value)
        
        # 数据库有直接填充
        if(len(cache_value)!=0):
            content_str = cache_value[0]
            operator_code = content_str['mnc']
            status = content_str['errcode']
            content_str = str(json.dumps(content_str))
            writeData(sheet, row_index, operator_code, content_str, status)
            continue;
            
        # 目前缓存的数据库不存在的情况 请求API 返回json字符串
        content_str = getLocation(0, lac_value, ci_value, 'json')
        real_data = json.loads(content_str)
        
        # 如果是移动的就写入
        if(real_data['errcode'] == 0):
            operator_code = 0;
            status = 0;
            writeData(sheet, row_index, operator_code, content_str, status)
            writeDB(conn, cursor, lac_value, ci_value, operator_code, real_data)
            continue;
        
        # 移动没有查到,换成联通的再调用API
        # 如果是联通的就写入
        content_str = getLocation(1, lac_value, ci_value, 'json')
        real_data = json.loads(content_str)
        if(real_data['errcode'] == 0):
            operator_code = 1;
            status = 0;
            writeData(sheet, row_index, operator_code, content_str, status)
            writeDB(conn, cursor, lac_value, ci_value, operator_code, real_data)
            continue;
        
        # 既不是移动也不是联通,触发异常逻辑
        operator_code = 0;
        status = 10001;
        writeData(sheet, row_index, operator_code, content_str, status)
        writeDB(conn, cursor, lac_value, ci_value, operator_code, real_data)
        
            
    saveData(wb,'lacci_test.xlsx')
    conn.close()


到了这里,关于根据基站位置区识别码(LCA)和小区识别(CI)获取经纬度的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • echarts中饼图的tooltip根据鼠标位置改变弹出位置

    echarts中的tooltip.position属性配置参考  echarts配置手册 问题:使用echarts绘制饼图,tooltip的弹出位置会遮挡住图表。 需求:tooltip的弹出位置在饼图外圈,不遮挡图表内容,切根据鼠标的位置而改变。 解决方法:在tooltip的配置项中对position进行配置,使用回调函数实现tooltip弹

    2024年02月08日
    浏览(38)
  • 高德根据经纬度,查询所在位置信息

    根据JSON对象获取信息 String cityInfo = GaoDeUtils.getAddressByJWD(request.getClog(), request.getClat()); JSONObject resultSucces = JSONObject.parse(cityInfo); JSONObject addr=resultSucces.getJSONObject(“regeocode”); AddressComponent addressComponent = JSON.parseObject(JSON.toJSONString(addr.get(“addressComponent”)), AddressComponent.class); 创

    2024年02月08日
    浏览(38)
  • js特效——根据鼠标位置移动的图片

    1、offsetX offset意为偏移量,是事件对象距左上角为参考原点的距离。以元素盒子模型的内容区域的左上角为参考点。不包括border。 2、clientX 事件对象相对于浏览器窗口可视区域的X,Y坐标(窗口坐标),可视区域不包括工具栏和滚动条 3、pageX 事件对象相对于整个文档的坐标以像素为

    2024年02月03日
    浏览(38)
  • Golang — 根据IP获取地理位置信息

    1 ip2region 2 geoip2-golang ip2region 是一个离线IP地址定位库和IP定位数据管理框架,10微秒级别的查询效率,提供了众多主流编程语言的 xdb 数据生成和查询客户端实现。 特点: 是一个开源的IP地理位置库。 标准化的数据格式 每个 ip 数据段的 region 信息都固定了格式:国家|区域|省

    2024年02月14日
    浏览(33)
  • java 圆形坐标计算(根据角度和边长计算位置)

    通过三角函数计算 圆形的任意弧形角度都对应一个直角三角形,通过三角函数来计算直角三角形的边长,从而得出每个角度下圆形坐标位置 o 为起始位置, r为半径,求圆形坐标位置 代码实现 设坐标 24,24 半径24 通过计算得出的结果和图形如下图 代码摘自Java 开发之 根据坐标

    2024年02月13日
    浏览(26)
  • 根据鼠标点击的位置来转换成UI坐标

    有时候游戏内一些Tips界面需要根据点击的位置来动态显示Tips界面的位置。 这个案例就很好用了。

    2024年02月16日
    浏览(21)
  • Unity根据目标点的位置计算Input输入

    当给一个目标点,如果目标直接去目标点我们可以直接让position指向目标点的position。 如果是转换输入呢? 举例:例如一个人物动画里有两个参数X和Y,X(- 1 ,1) 表示向左走和向右走,Y (-1 , 1) 向后和向前走。 如果我给一个目标点,如何计算应该给动画什么样的数值就可以呢

    2024年02月16日
    浏览(31)
  • (Java版)根据ip获取地理位置以及相关信息

    1.首先我们需要进入地图开放平台的官网,根据提示注册账号,以百度地图为例: https://lbsyun.baidu.com/ 我们新用户登录之后会弹出这个页面,选择个人爱好者进入完成注册 成功之后我们会进入到下面这个页面,如果没有申请ak的小伙伴在控制台看板这一块是有一个流程指引的

    2024年02月08日
    浏览(23)
  • pytorch 根据bool矩阵取出tensor中对应位置元素

    1. bool矩阵当做索引(类型是:BoolTensor) 结果为一维向量(因为bool矩阵二维的,根据bool矩阵中True对应位置,把tensor数据中相应位置中的值取出来,组成一个新的一维tensor向量) 输出结果: 2. 一维bool向量当做索引(类型是:BoolTensor) 第一个例子:结果为一维向量(target是

    2023年04月10日
    浏览(34)
  • 根据手机指南针经纬度在地图上找到其位置

    使用手机指南针获取经纬度,然后在地图上找到位置。 1、使用手机指南针获取经纬度: 2、将度分秒转换为度: 分/60+秒/3600+整数度数,得到以度为单位的数值 手机经纬度:117.1291666,31.842777 3、坐标系转换: 地图坐标系转换 - 在线工具 输入手机经纬度:117.1291666,31.842777 得到

    2024年02月09日
    浏览(26)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包