Login

Simple ping ICMP with jquery

Author:
magik_cypress
Posted:
September 30, 2011
Language:
Python
Version:
1.3
Score:
1 (after 1 ratings)

Ping ICMP ip with jquery.

 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
# index.html

 <ul>
     <li>192.168.1.22 [Status: <span class="address" id="ip_192_168_1_22">Unknown</span> ]</li>
     <li>192.168.0.2 [Status: <span class="address" id="ip_192_168_0_2">Unknown</span> ]</li>
     <li>192.168.0.3 [Status: <span class="address" id="ip_192_168_0_3">Unknown</span> ]</li>
 </ul>


 <script type="text/javascript">

 var items;

 function updateStatus(index) {
        if (index == items.size()) {return;}
                var item = items.eq(index);
                var attrId = item.attr("id");
                var address = attrId.replace('ip_', '');
                address = address.replace(/_/g, '.');
                $.get('/ping/' + address,
                function(response) {
                        item.html(response);
                        $("ul").trigger('updated', [index]);
                });
 }

 $(document).ready(function() {
        items = $(".address");
        $("ul").bind('updated',
        function(event, index) {
                updateStatus(index + 1);
        });
        updateStatus(0);
 });

 </script>

 # urls.py

 url(r'^ping/(?P<address>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/$', ping),

 # views.py

 def ping(request, address=None):
     if os.system('ping -c3 -q ' + address):
         msg = "Ping OK"
     else:
         msg = "No response"
     return HttpResponse(msg)

Inspiration : http://www.grenadepod.com/2009/11/13/query-data-from-django-site-with-jquery/

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

reighnman (on July 21, 2014):

Will this work with just html/jquery/py or does it require django?

#

Please login first before commenting.