Skip to content
Snippets Groups Projects
Commit 7d9d4bfb authored by Gayan Rathnathilake's avatar Gayan Rathnathilake
Browse files

Shodan commit-1

parent 439f0591
Branches
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (backend)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (backend)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
No preview for this file type
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ShodanScanConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'shodan_scan'
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import ShodanScanView
urlpatterns = [
path('shodan-scan/', ShodanScanView.as_view(), name='shodan_scan'),
]
\ No newline at end of file
import shodan
def shodan_scan(api_key, ips):
api = shodan.Shodan(api_key)
scan_results = []
for ip in ips:
try:
# Host information
host_info = api.host(ip)
# Append scan results to the list
scan_results.append({
'ip_address': ip,
'open_ports': [{
'port': port_info['port'],
'protocol': port_info['_shodan']['module'],
'banner': port_info.get('banner', None)
} for port_info in host_info['data']],
'geolocation': {
'country': host_info.get('country_name', None),
'city': host_info.get('city', None),
'latitude': host_info.get('latitude', None),
'longitude': host_info.get('longitude', None)
},
'vulnerabilities': [{
'vuln': host_info['vulns'][vuln]['summary']
} for vuln in host_info.get('vulns', {})]
})
except shodan.APIError as e:
print(f"Error: {e}")
return scan_results
\ No newline at end of file
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework.views import APIView
from .utils import shodan_scan
from rest_framework.permissions import AllowAny
class ShodanScanView(APIView):
permission_classes = [AllowAny]
@csrf_exempt
def post(self, request, format=None):
api_key = '39NV6HlSBtbQCmp0oKOmHZp51pdC99CA'
ip_list = request.data.get('ips', [])
scan_results = shodan_scan(api_key, ip_list)
return JsonResponse({'scan_results': scan_results}, safe=False)
......@@ -34,6 +34,7 @@ INSTALLED_APPS = [
"rest_framework",
"rest_framework_simplejwt",
"breach_check",
"shodan_scan",
]
......
......@@ -11,5 +11,6 @@ urlpatterns = [
path('api/breaches/', include('breach_check.urls')), # Include breaches app URLs
path('haveibeenpwned/<str:identifier>/', have_i_been_pwned, name='have_i_been_pwned'),
path('haveibeenpwned/passwords/<str:identifier>/', breached_password_info, name='breached_password_info'),
path('', include('shodan_scan.urls')),
# Add other URL patterns as needed
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment