【发布时间】:2021-03-18 18:28:56
【问题描述】:
我正在寻找一种方法来 ping 我的网络上的本地设备,例如我在终端中使用 de ping 命令来 ping 我的路由器或任何其他连接的设备。 我已经找到了 ping 像 google.com 这样的服务器的方法,但它似乎不适用于本地地址。 这可能吗? 这是我的打字稿代码:
private source = interval(3000);
constructor(private _http: HttpClient) { }
...
getStatutDevice(ip: string){
//IP Value look like "192.168.1.20" for example
this.source.subscribe(() => {
this._http.get(ip, { observe: 'response' })
.pipe(first())
.subscribe(resp => {
if (resp.status === 200 ) {
console.log(true);
} else {
console.log(false);
}
}, err => console.log(err));
});
}
我在控制台中收到此错误:
zone-evergreen.js:2863 GET http://localhost:4200/192.168.1.20 404(未找到)
如果我在 IP 地址前加上“https://”,我得到:
GET https://192.168.1.20/net::ERR_CONNECTION_REFUSED
我不知道找到解决方案意味着什么。
【问题讨论】:
标签: angular typescript ping