Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netbox integration for IP lookup #112

Open
rubydhash opened this issue Sep 18, 2024 · 1 comment
Open

Netbox integration for IP lookup #112

rubydhash opened this issue Sep 18, 2024 · 1 comment

Comments

@rubydhash
Copy link

The IP lookup through WHOIS is very useful; however, for internal IPs, it would be great to query the NetBox API to retrieve IP context. Is that already possible, or would it need to be implemented?

@mbolli
Copy link
Owner

mbolli commented Sep 18, 2024

Sounds like a good idea. This would need to be implemented. The logic is here:

ip_link_handler = (a) => {
const ip = a.innerHTML;
const ignoredFields = ['country_', 'timezone_', 'currency_'];
const checkIp = async (ip) => {
const ipWhoisResponse = await fetch('https://ipwhois.app/json/' + ip);
const ipWhoisData = await ipWhoisResponse.json();
const hostResponse = await fetch('../api/host/?ip=' + ip);
const hostData = (!hostResponse.ok) ? 'IP could not be resolved' : await hostResponse.json();
return {
ipWhoisData: ipWhoisData,
hostData: hostData
}
}
const modal = new bootstrap.Modal('#modal', {});
const modalTitle = document.querySelector('#modal .modal-title');
const modalBody = document.querySelector('#modal .modal-body');
const modalLoader = document.querySelector('#modal .modal-loader');
modalBody.innerHTML = modalLoader.outerHTML;
modalBody.querySelector('.modal-loader').classList.remove('d-none');
modalTitle.innerHTML = 'Info for IP: ' + ip;
modal.show();
// make request and display data
checkIp(ip).then((data) => {
console.log(data);
// create table
let markup = '<table class="table table-striped">';
for (const [key, value] of Object.entries(data.ipWhoisData)) {
// if key starts with any of ignoredFields values, skip it
if (ignoredFields.some(field => key.startsWith(field))) continue;
markup += '<tr><th>' + key + '</th><td>' + value + '</td></tr>';
}
markup += '</table>';
// add heading and flag
let flag = data.ipWhoisData.country_flag ? '<img src="' + data.ipWhoisData.country_flag + '" alt="' + data.ipWhoisData.country + '" title="' + data.ipWhoisData.country + '" style="width: 3rem" />' : '';
let heading = '<h3>' + ip + ' ' + flag + '</h3>';
heading += '<h4>Host: ' + data.hostData + '</h4>';
// replace loader with content
modalBody.innerHTML = heading + markup;
});
};

Optimally this would be opt-in via settings file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants