在Javascript中使用ipinfo创建标记表
所以我需要用Javascript编写一个函数,它使用ipinfo.io获取给定IP地址的一些信息。函数需要在降价表中返回此信息。我在互联网上搜索关于如何做到这一点的答案,但找不到任何东西。。。有人能帮我吗? 非常感谢:) 塔尔 到目前为止,我得到的是:在Javascript中使用ipinfo创建标记表,javascript,markdown,Javascript,Markdown,所以我需要用Javascript编写一个函数,它使用ipinfo.io获取给定IP地址的一些信息。函数需要在降价表中返回此信息。我在互联网上搜索关于如何做到这一点的答案,但找不到任何东西。。。有人能帮我吗? 非常感谢:) 塔尔 到目前为止,我得到的是: var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; var ip = require("ip"); function queryIPInfo(ipAddr) { try
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var ip = require("ip");
function queryIPInfo(ipAddr) {
try {
if (!(ip.isV4Format(ipAddr) || ip.isV6Format(ipAddr)))
throw("Not a valid IP address error");
}
catch (e) {console.log("Error: "+e);}
var xmlReq = new XMLHttpRequest();
xmlReq.open('GET', "https://ipinfo.io/"+ipAddr+"/json", true);
xmlReq.send();
xmlReq.onreadystatechange = function(e) {
if (xmlReq.readyState == 4 && xmlReq.status == 200) {
var response = JSON.parse(xmlReq.responseText);
// put the info from response in a markdown table and return it
}
};
}
queryIPInfo(process.argv[2]) 表不是核心降价规范的一部分。我知道它们不是,但这仍然是我的任务:)它是在我通过一次工作面试后交给我的,作为测试我能力的另一个阶段,所以我猜有可能创建一个表并返回它。问题是怎么做?A给了我一个看起来很有趣的答案。其余的取决于你的能力;-)