如何解决检查 UUID 是否包含在 pastebin 中
我想检查一下我的 UUID 是否包含在我的 pastebin 中。
知道如何在 JavaScript 中检查吗?
// GET UUID
const execSync = require("child_process").execSync;
const { type } = require("os");
const { SSL_OP_EPHEMERAL_RSA } = require("constants");
let response = execSync("wmic csproduct get uuid");
let serial = String(response).split("\n")[1];
console.log(serial);
async function fetchText() {
let response = await fetch("https://pastebin.com/raw/4hxgLxyd");
let data = await response.text();
console.log(data.indexOf(serial));
if (data.indexOf(serial) !== -1) {
console.log("included");
} else {
console.log("not included");
}
}
fetchText();
我是 JS 新手 - 在 Python 中我知道如何使用请求命令检查它。
有人知道如何在 JS 中处理这个吗?
按照我的要求,我的 Python 代码:
def init(): # check HWID
try:
HWID = subprocess.check_output('wmic csproduct get uuid').decode().split('\n')[1].strip()
except:
cmd = "system_profiler SPHardwareDataType | grep 'Serial Number' | awk '{print $4}'"
result = subprocess.run(cmd,stdout=subprocess.PIPE,shell=True,check=True)
HWID = result.stdout.decode().strip()
print('Checking license...')
# -------------------------------------------
# Below this - I need the code for JavaScript
# -------------------------------------------
r = requests.get('https://pastebin.com/xxx')
try:
if HWID in r.text:
pass
else:
print('[ERROR] HWID not registered!')
print(f'HWID: {HWID}')
time.sleep(5)
sys.exit(0)
except:
print('[ERROR] Failed to initiate')
time.sleep(5)
sys.exit(0)
print(f'HWID: {HWID}')
print('--- License is valid ---')
解决方法
在 javascript 中,您可以使用 indexOf
来搜索字符串的出现。如果不存在,函数将返回-1,否则索引第一次出现。
此外,请确保您考虑区分大小写以及破折号和空格的位置。
var str = "Hello world,welcome to the universe.";
var n = str.indexOf("welcome");
请参阅 Node.Js documentation 以执行 http 请求。
// GET UUID
const execSync = require("child_process").execSync;
const response = execSync("wmic csproduct get uuid");
const serial = String(response).split("\n")[1].replace("-","").trim().toLowerCase();
const https = require('https')
const options = {
hostname: 'pastebin.com',port: 443,path: '/xxx',method: 'GET'
}
const req = https.request(options,res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data',d => {
var dnorm= d.replace("-","").trim().toLowerCase();
process.stdout.write(dnorm.indexOf(serial))
})
})
req.on('error',error => {
console.error(error)
})
req.end()
由于出现空格或编码问题,请手动比较字符串的内容:
function debugComp(a,b)
{
a= a.toString().trim();
b= a.toString().trim();
console.log("a: '" + a + "' - Length: " + a.length);
console.log("b: '" + b + "' - Length: " + b.length);
if(a.indexOf(b)>-1)
{
console.log("Found at index " + a.indexOf(b));
}
else if(a.length==b.length)
{
for(var i=0; i< a.length; i++)
{
console.log("a[" + i + "]= '" + a[i] + "' - b[" + i + "] = '" + b[i]);
console.log("a[" + i + "] == b[" + i+ "] = " + (a[i]==b[i]));
}
}
else {
console.log("Strings have different lengths");
}
}
debugComp("D340D9AE-A43F-DF47-AFED-A93222AB3646","D340D9AE-A43F-DF47-AFED-A93222AB3646");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。