mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-01-22 12:34:17 +00:00
Implement basic api export of all active hosts
Done by zzz request. Export all seen hosts in json format { b32: last_seen }.
This commit is contained in:
parent
e4f5ae4a6c
commit
3880aa9f0f
0
pyi2phosts/api/__init__.py
Normal file
0
pyi2phosts/api/__init__.py
Normal file
5
pyi2phosts/api/urls.py
Normal file
5
pyi2phosts/api/urls.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django.conf.urls import *
|
||||||
|
|
||||||
|
urlpatterns = patterns('pyi2phosts.api.views',
|
||||||
|
url(r'^all/$', 'all'),
|
||||||
|
)
|
16
pyi2phosts/api/views.py
Normal file
16
pyi2phosts/api/views.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import simplejson as json
|
||||||
|
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
from pyi2phosts.postkey.models import i2phost
|
||||||
|
from pyi2phosts.lib.utils import get_b32
|
||||||
|
|
||||||
|
def all(request):
|
||||||
|
"""Return all hosts in { "b32": "last seen timestamp" } form. Implemented by zzz request. """
|
||||||
|
# all hosts seen at least once
|
||||||
|
queryset = i2phost.objects.exclude(last_seen=None)
|
||||||
|
json_dict = {}
|
||||||
|
for host in queryset:
|
||||||
|
# pass last_seen to json in unixtime
|
||||||
|
json_dict[get_b32(host.b64hash)] = host.last_seen.strftime("%s")
|
||||||
|
return HttpResponse(json.dumps(json_dict), mimetype="application/json")
|
@ -23,6 +23,7 @@ urlpatterns = patterns('',
|
|||||||
(r'^search/$', include('pyi2phosts.search.urls')),
|
(r'^search/$', include('pyi2phosts.search.urls')),
|
||||||
(r'^postkey/', include('pyi2phosts.postkey.urls')),
|
(r'^postkey/', include('pyi2phosts.postkey.urls')),
|
||||||
(r'^jump/', include('pyi2phosts.jump.urls')),
|
(r'^jump/', include('pyi2phosts.jump.urls')),
|
||||||
|
(r'^api/', include('pyi2phosts.api.urls')),
|
||||||
(r'^i18n/', include('django.conf.urls.i18n')),
|
(r'^i18n/', include('django.conf.urls.i18n')),
|
||||||
# Example:
|
# Example:
|
||||||
# (r'^pyi2phosts.', include('pyi2phosts.foo.urls')),
|
# (r'^pyi2phosts.', include('pyi2phosts.foo.urls')),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user