代码如下:
use HTTP::UserAgent; use JSON::Tiny; my $check-url = ‘www.baidu.com‘; #say @*ARGS[0]; #检测命令行参数 if @*ARGS != 0 { $check-url = @*ARGS[0].lc; }else{ say ‘no http/https, eg:‘; say ‘cms-check.p6 www.target.com‘; exit; } my $url = ‘http://120.24.44.134/yunxi-web/public/home/index‘; #say $check-url; #cookies my $cookie = HTTP::Cookies.new; #创建 一个Ie my $ua =HTTP::UserAgent.new; $cookie.set-cookie(‘Set-Cookie:XSRF-TOKEN=eyJpdiI6ImQyNWhPQjVcL2YyeTEzTnFiaUZXbUJRPT0iLCJ2YWx1ZSI6ImMxTzM5SDVrQldJVmF0NVduTEhsSXZEd2xZV05lZ2VOM2NueXhYdjM3RkhHNm1md3ZPYkpkeUxvdVlwSzg2Rk5pMkFVcEhVWWdQYjJDVmhqeFdsaXlRPT0iLCJtYWMiOiJkODU1NjUzM2Q1NzgwN2RhYTBhZDI3MTdmYTZiNDFhNzYwMDg5MmFlZDA0MWUyNWEyNmZjYjZhNmE3MGIyMjZhIn0%3D; laravel_session=eyJpdiI6ImFSeGFmSWZBTXZseTdvNDFLVFVxdEE9PSIsInZhbHVlIjoiWGl5TDFRcTZydWJjVzlleUxRM1N4RUlReUVQdDZVTnNZMjNXb0FtWDE3azFuTkFRSXVNYVNzMit3dWdJaDcxSk95T0VEcjBDZVFoY1lVR0NURnBwUEE9PSIsIm1hYyI6ImEwNjM3OGVjZGUzYTk4ODY4NzJhMjg0ZTAzZDYwMGYwYTU2YzhjYzZmMmJjNTZiMTdmMDIyMmJkNzc0NDI4NTgifQ%3D%3D‘); #request my $request = HTTP::Request.new; $request.header.field(:X-Requested-With<XMLHttpRequest>); $request.header.field(:Referer($url)); $request.add-cookies($cookie); $request.set-method: ‘POST‘; $request.uri: $url; #上面设置请求头信息与cookie与请求方法 my %postdata = :_token<ZgA9ggjV9AGGNEO2dfDdeanuLlLbYzjiBGxAnq6h>,:update<‘‘>,:http<http%3A%2F%2F>,:url($check-url),:level<1>; $request.add-form-data(%postdata); #设置POST参数, 这个POST数据中的HTTP键其实是可以设置是HTTP还是HTTPS的, 这里为了方便, 全部设置检测试URL为HTTP类型 my $result = $ua.request($request); #发送请求 #say $result.request.Str; #say $result.content; my $json = from-json($result.content); #将JSON转化为PERL结构代码 #say $json.perl; #say $json[0].WHAT; say ‘URL: ‘~$check-url; #当查询到数据时,数组第一个参数会自动转为HASH型 if $json[0].WHAT.perl ne ‘Hash‘ { say ‘Unknown‘; }else{ say ‘CMS: ‘~$json[0]<name>; } #用法: #cms-check.p6 / cms-check.p6 url #不要http或https开头
使用前请安装好 perl6
再用zef安装好所用的模块:
zef install HTTP::UserAgent --force; zef install JSON::Tiny --force;
效果如下:
一般来说, 查不到CMS或服务器系统信息, 就返回未知(Unknown)
有时没法转换JSON时会出错, 下次有时间再改版一下。
时间: 2024-10-06 00:46:07