OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how to ping an IP and get all the statitics using HTML CSS and JS [closed]

  • Thread starter Thread starter Aravind
  • Start date Start date
A

Aravind

Guest
I'm trying to make a website where users can enter an ip address or a host name, the site should ping and provide the user with all the details and statitics.

i tried using siterelic api but it threw cors error so i added no-cors mode in header, now it is throwing 403 error

Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <header>
        <h1 class="heading">PING STATITICS</h1>
    </header>
    <main>
        <input type="text" id="ipaddr">
        <button onclick="fetchData()">
            <span>
                GO
            </span>
        </button>
    </main>
    <section>
        <div id="results">
            info here
        </div>
    </section>

    <script src="script.js"></script>
</body>
</html>

Code:
    const input = document.getElementById('ipaddr')

    const apiUrl = "https://api.siterelic.com/ping";

    const headers = {
        "x-api-key": "my-api-key",
        "Content-Type": "application/json",
    }

    function fetchData(){
        const data = {
            url: input.value
        }

        fetch(apiUrl, {
            method: "POST",
            mode: 'no-cors',
            headers: headers,
            body: JSON.stringify(data)

        }).then((response) => {
            if(!response.ok){
                console.log("error")
            }
            return response.json()
        }).then((data) => {
            console.log(data);
        })
    }

<p>I'm trying to make a website where users can enter an ip address or a host name, the site should ping and provide the user with all the details and statitics.</p>
<p>i tried using siterelic api but it threw cors error so i added no-cors mode in header, now it is throwing 403 error</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1 class="heading">PING STATITICS</h1>
</header>
<main>
<input type="text" id="ipaddr">
<button onclick="fetchData()">
<span>
GO
</span>
</button>
</main>
<section>
<div id="results">
info here
</div>
</section>

<script src="script.js"></script>
</body>
</html>
</code></pre>
<pre><code> const input = document.getElementById('ipaddr')

const apiUrl = "https://api.siterelic.com/ping";

const headers = {
"x-api-key": "my-api-key",
"Content-Type": "application/json",
}

function fetchData(){
const data = {
url: input.value
}

fetch(apiUrl, {
method: "POST",
mode: 'no-cors',
headers: headers,
body: JSON.stringify(data)

}).then((response) => {
if(!response.ok){
console.log("error")
}
return response.json()
}).then((data) => {
console.log(data);
})
}
</code></pre>
 

Latest posts

Top