-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPAddress.html
More file actions
166 lines (156 loc) · 4.67 KB
/
Copy pathIPAddress.html
File metadata and controls
166 lines (156 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IP Address Info</title>
<style>
body {
font-family: sans-serif;
margin: 20px;
background: #f0f0f0;
}
.container {
background: #fff;
padding: 20px;
max-width: 600px;
margin: auto;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
h1 {
margin-top: 0;
}
pre {
white-space: pre-wrap;
word-break: break-word;
background: #f8f8f8;
padding: 10px;
border-radius: 4px;
}
button {
margin-right: 10px;
padding: 10px 15px;
cursor: pointer;
border: none;
border-radius: 4px;
background: #0080ff;
color: #fff;
font-size: 14px;
}
button:hover {
background: #0059b3;
}
.loading {
font-style: italic;
color: gray;
}
</style>
</head>
<body>
<div class="container">
<h1>Your IP & Network Info</h1>
<div id="ip-details" class="loading">
Fetching details...
</div>
<div style="margin-top:20px;">
<button onclick="copyAllInfo()">Copy Info</button>
<button onclick="shareAllInfo()">Share Info</button>
</div>
</div>
<script>
const ipDetailsDiv = document.getElementById('ip-details');
// Data structure to hold results
let ipData = {
ipv4: null,
ipv6: null,
details: {}
};
// 1) Fetch IPv4
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
ipData.ipv4 = data.ip || 'Unavailable';
updateDisplay();
})
.catch(err => {
ipData.ipv4 = 'Error fetching IPv4';
updateDisplay();
});
// 2) Fetch IPv6 (some connections might not provide IPv6)
fetch('https://api64.ipify.org?format=json')
.then(response => response.json())
.then(data => {
ipData.ipv6 = data.ip || 'Unavailable';
updateDisplay();
})
.catch(err => {
ipData.ipv6 = 'Error fetching IPv6';
updateDisplay();
});
// 3) Fetch geolocation & additional info from ipapi.co
fetch('https://ipapi.co/json/')
.then(response => response.json())
.then(info => {
ipData.details = info;
updateDisplay();
})
.catch(err => {
ipData.details = { error: 'Error fetching extra details' };
updateDisplay();
});
// Update the display once data is received
function updateDisplay() {
let infoHtml = '';
infoHtml += 'IPv4 Address: ' + (ipData.ipv4 ? ipData.ipv4 : '...') + '\n';
infoHtml += 'IPv6 Address: ' + (ipData.ipv6 ? ipData.ipv6 : '...') + '\n\n';
if (Object.keys(ipData.details).length === 0) {
infoHtml += 'Extra Details: Fetching...';
} else if (ipData.details.error) {
infoHtml += 'Extra Details: ' + ipData.details.error;
} else {
// Display everything we got from the location API
infoHtml += 'City: ' + (ipData.details.city || 'N/A') + '\n';
infoHtml += 'Region/State: ' + (ipData.details.region || 'N/A') + '\n';
infoHtml += 'Country: ' + (ipData.details.country_name || 'N/A') + '\n';
infoHtml += 'Postal Code: ' + (ipData.details.postal || 'N/A') + '\n';
infoHtml += 'Latitude, Longitude: ' + (ipData.details.latitude + ', ' + ipData.details.longitude || 'N/A') + '\n';
infoHtml += 'Organization: ' + (ipData.details.org || 'N/A') + '\n';
infoHtml += 'ASN: ' + (ipData.details.asn || 'N/A') + '\n';
infoHtml += 'Timezone: ' + (ipData.details.timezone || 'N/A') + '\n';
infoHtml += 'UTC Offset: ' + (ipData.details.utc_offset || 'N/A') + '\n';
infoHtml += 'Currency: ' + (ipData.details.currency || 'N/A') + '\n';
infoHtml += 'Country Calling Code: ' + (ipData.details.country_calling_code || 'N/A') + '\n';
infoHtml += 'Languages: ' + (ipData.details.languages || 'N/A') + '\n';
infoHtml += 'User Agent (if provided): ' + (ipData.details.user_agent || 'N/A') + '\n';
}
ipDetailsDiv.innerHTML = '<pre>' + infoHtml + '</pre>';
ipDetailsDiv.classList.remove('loading');
}
// Copy all IP & info to clipboard
function copyAllInfo() {
let textToCopy = ipDetailsDiv.innerText;
navigator.clipboard.writeText(textToCopy)
.then(() => {
alert('IP & Info copied to clipboard!');
})
.catch(err => {
alert('Failed to copy: ' + err);
});
}
// Share via native share dialog (if supported)
function shareAllInfo() {
if (navigator.share) {
navigator.share({
title: 'My IP & Network Info',
text: ipDetailsDiv.innerText
})
.catch(err => {
alert('Share failed: ' + err);
});
} else {
alert('Native Web Share not supported on this browser.');
}
}
</script>
</body>
</html>