Ungleich/app.js
2018-12-31 15:40:15 +01:00

84 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const IPV4_EX = new RegExp("")
const regex = RegExp(/^((([09A-Fa-f]{1,4}:){7}[09A-Fa-f]{1,4})|(([09A-Fa-f]{1,4}:){6}:[09A-Fa-f]{1,4})|(([09A-Fa-f]{1,4}:){5}:([09A-Fa-f]{1,4}:)?[09A-Fa-f]{1,4})|(([09A-Fa-f]{1,4}:){4}:([09A-Fa-f]{1,4}:){0,2}[09A-Fa-f]{1,4})|(([09A-Fa-f]{1,4}:){3}:([09A-Fa-f]{1,4}:){0,3}[09A-Fa-f]{1,4})|(([09A-Fa-f]{1,4}:){2}:([09A-Fa-f]{1,4}:){0,4}[09A-Fa-f]{1,4})|(([09A-Fa-f]{1,4}:){6}((b((25[05])|(1d{2})|(2[04]d)|(d{1,2}))b).){3}(b((25[05])|(1d{2})|(2[04]d)|(d{1,2}))b))|(([09A-Fa-f]{1,4}:){0,5}:((b((25[05])|(1d{2})|(2[04]d)|(d{1,2}))b).){3}(b((25[05])|(1d{2})|(2[04]d)|(d{1,2}))b))|(::([09A-Fa-f]{1,4}:){0,5}((b((25[05])|(1d{2})|(2[04]d)|(d{1,2}))b).){3}(b((25[05])|(1d{2})|(2[04]d)|(d{1,2}))b))|([09A-Fa-f]{1,4}::([09A-Fa-f]{1,4}:){0,5}[09A-Fa-f]{1,4})|(::([09A-Fa-f]{1,4}:){0,6}[09A-Fa-f]{1,4})|(([09A-Fa-f]{1,4}:){1,7}:))$/)
var addresses = []
var date = []
var ipv4_v6 = []
function Ip4OrIp6(ipAddress){
if(ipAddress.length == 39){
ipv4_v6.push(1);
}else{
ipv4_v6.push(-1);
}
}
// Refactor getStudents and getScores to return Promise for their response bodies
function getData(){
return fetch(`address.json`, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
}).then((response) => response.json())
};
getData().then((data)=>{
data.forEach(element => {
date.push(element.date);
Ip4OrIp6(element.ip);
});
console.log(date);
console.log(ipv4_v6);
date.sort((a, b)=>{
return new Date(b) - new Date(a)
})
var ctx = document.getElementById("myChart").getContext('2d');
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels:date ,
datasets: [{
label: "Statistics for IPV4 and IPV6",
data:ipv4_v6,
}
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Statistics for IPV4 and IPV6'
}
}
})
})
//Fetch call to get data from addresses json file
// async function retrieveIpAdresses(){
// await fetch('./address.json').then(response => {
// response.json();
// }).then(data => {
// data.forEach(element=>{
// console.log(element)
// date.push(element.date)
// })
// }).catch(err => {
// err = err
// });
// }