Login

Simple ping ICMP with jquery

Author:
magik_cypress
Posted:
September 30, 2011
Language:
Python
Version:
1.3
Tags:
django jquery ping
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. Client-side django template with jQuery by ksjun 6 years, 12 months ago
  2. jQuery Autocomplete by zeeg 8 years ago
  3. save form in ajax with jquery in django by ralphleyga 4 years, 10 months ago
  4. jQuery slugify plugin by girasquid 6 years, 1 month ago
  5. Slideshow (Random Image Display) - Using Jquery by veeravendhan 5 years, 11 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.