美文网首页
python3.7+beautifulSoup4+lxml UD

python3.7+beautifulSoup4+lxml UD

作者: 格雷s | 来源:发表于2019-10-08 10:42 被阅读0次

    1.配置.mobileconfig
    新建udid.mobileconfig文件

    <!--参考:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/iPhoneOTAConfiguration/ConfigurationProfileExamples/ConfigurationProfileExamples.html-->
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <dict>
            <key>PayloadContent</key>
            <dict>
                <key>URL</key>
                <string>http://10.0.4.37:7777/catchUdid</string>
                <key>DeviceAttributes</key>
                <array>
                    <string>UDID</string>
                    <string>IMEI</string>
                    <string>ICCID</string>
                    <string>VERSION</string>
                    <string>PRODUCT</string>
                </array>
            </dict>
            <key>PayloadOrganization</key>
            <string>com.gelei.tt</string>
            <key>PayloadDisplayName</key>
            <string>查询设备UDID</string>
            <key>PayloadVersion</key>
            <integer>1</integer>
            <key>PayloadUUID</key>
            <string>eb185249-4b9d-4af6-8537-d8553180d899</string>
            <key>PayloadIdentifier</key>
            <string>dev.skyfox.profile-service</string>
            <key>PayloadDescription</key>
            <string>本文件仅用来获取设备ID</string>
            <key>PayloadType</key>
            <string>Profile Service</string>
        </dict>
    </plist>
    
    

    其中URL为服务端的响应接口,用于接收设备端返回的xml数据

    2.新建html文件,配置mobileconfig入口
    config.html

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="application/x-apple-aspen-config; charset=utf-8" />
            <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport" id="viewport" />
            <title>获取您的UDID</title>
            <body>
                <div id="content">
                    <a class="buttons" href="udid_sign.mobileconfig" target="_blank">点击获取您的UDID</a>
                </div>
            </body>
    </html>
    
    

    3.服务端接口开发
    使用beautifulSoup4+lxml解析数据

    import flask,json
    import bs4, lxml
    server=flask.Flask(__name__)#__name__代表当前的python文件。把当前的python文件当做一个服务启动
    
    @server.route('/catchUdid',methods=['get','post'])#只有在函数前加上@server.route (),这个函数才是个接口,不是一般的函数
    def catchUdid():
        b_data = flask.request.data
        data_str = str(b_data).split('<?xml')[-1].split('</plist>')[0]
        data_str = '<?xml{}</plist>'.format(data_str).replace('\\t', '').replace('\\n', '')
        soup = bs4.BeautifulSoup(data_str, features='xml')
        xml = soup.find('dict')
        keys = []
        values = []
        for item in xml.find_all():
            if item.name == 'key':
                keys.append(item.text)
            else:
                values.append(item.text)
        print('=======start===')
        print(keys)
        print(values)
        print('=======end===')
        return flask.redirect(flask.url_for('handleUdid',u_id=values[-2]),code=301)
    
    @server.route('/handleUdid/<u_id>',methods=['get','post'])
    def handleUdid(u_id=None):
        data={'u_id':u_id}
        return json.dumps(data)
    
    server.run(port=7777,debug=True,host='0.0.0.0')
    

    注意一点要采用重定向转发code为301,否则后续会安装描述文件失败

    4.本地测试,python3.7开启web服务

    python3.7 -m http.server 8001
    

    5.启动服务端

    python3.7 pyservice.py 
    

    4.手机端访问config.html

    http://10.0.4.37:8001/config.html
    

    点击后会安装描述文件,但是获取到的描述文件显示的红色未验证,我们需要对.mobileconfig文件进行签名,这里借助网上的签名脚本:https://github.com/nmcspadden/ProfileSigner,执行:

     ./profile_signer.py -n "3rd Party Mac Developer Application" sign AcrobatPro.mobileconfig AcrobatProSigned.mobileconfig
    

    "3rd Party Mac Developer Application"是签名的证书名称,具体可以从钥匙串中查看

    5.再次访问config.html,点击'获取UDID',安装描述文件,现在应该显示绿色‘已验证’,点击安装,稍后服务端会接收到xml数据流,通过服务端的上述处理,可以获取到UDID

    相关文章

      网友评论

          本文标题:python3.7+beautifulSoup4+lxml UD

          本文链接:https://www.haomeiwen.com/subject/exzvpctx.html