chenoi
chenoi

Reputation: 565

Python ping script always failed on 1st attempt

I'm facing failure issue when run python script to ping nodes in my network and it always fail on my 1st attempt ...when run again...it works. My environment is linux machine and I ping to only 3 devices.

To test it I just create simple script. For 1st attempt it will failed and if i run the script again and again...everything ok... then after i left for 15mins-30mins... I run and it will failed...then run again...ok... May I know if you guyz facing this kind of issue.

The code as follows;

def verify_ping():
    ipadd = "192.168.1.1"
    response = os.system("ping -c 1 " + ipadd)

    if response == 0:
        ipstatus = "UP"
    else:
        ipstatus = "DOWN"

    return ipstatus

ping_status = verify_ping()

The PING failure a follows

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
From 192.168.1.1 icmp_seq=1 Redirect Host(New nexthop: 192.168.1.100)

--- 192.168.1.1 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

Ping OK

PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=250 time=1.33 ms

--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

At the same time I do continues ping to the IP and so far the IP up and reachable. Maybe someone face the issue or maybe something that i need to add to the script. Please advise further and thank you for your time.

Upvotes: 0

Views: 222

Answers (1)

Valentin BOUSSON
Valentin BOUSSON

Reputation: 149

It may be related to an ARP issue. It may depends on the network architecture of your environment, and parameters of your network devices

(see https://learningnetwork.cisco.com/thread/85577)

Upvotes: 1

Related Questions