import Foundation
func checkSpam(ipAddress: String) {
// Validate the IP address
if ipAddress.range(of: #"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"#, options: .regularExpression) == nil {
print("Invalid IP address format")
return
}
// List of spam databases to check
let spamDatabases = [
"b.barracudacentral.org",
"bl.spamcop.net",
"dnsbl.sorbs.net",
"zen.spamhaus.org"
]
// Check each database for the IP address
for db in spamDatabases {
let query = ipAddress + "." + db
guard let addr = try? DNSResolver.resolve(query: query) else {
print("Error checking \(ipAddress) in \(db)")
continue
}
// Check if the IP address is listed
if addr == "127.0.0.2" || addr == "::1" {
print("\(ipAddress) found in \(db)")
} else {
print("\(ipAddress) not found in \(db)")
}
}
}
struct DNSResolver {
static func resolve(query: String) throws -> String {
// Perform DNS lookup here
// Simulating DNS lookup result for demonstration
// In real-world implementation, you would use a DNS resolver library or system call
return "127.0.0.2"
}
}
// Example usage
let ipToCheck = "123.456.789.10" // Replace this with the IP address you want to check
checkSpam(ipAddress: ipToCheck)
यह स्क्रिप्ट सबसे पहले एक नियमित अभिव्यक्ति का उपयोग करके आईपी पते के प्रारूप को मान्य करती है। फिर, यह DNS क्वेरीज़ का निर्माण करके कई स्पैम डेटाबेस के विरुद्ध आईपी पते की जाँच करता है। अंत में, यह प्रिंट करता है कि क्या आईपी पता प्रत्येक डेटाबेस में पाया जाता है या नहीं। ध्यान दें कि DNSResolver
स्ट्रक्चर वास्तविक DNS समाधान करने के लिए एक प्लेसहोल्डर है, और वास्तविक दुनिया के परिदृश्य में, आपको DNS रिज़ॉल्वर लाइब्रेरी या सिस्टम कॉल का उपयोग करके इस कार्यक्षमता को लागू करने की आवश्यकता होगी।
टिप्पणियाँ (0)
यहां अभी तक कोई टिप्पणी नहीं है, आप पहले हो सकते हैं!