Python Forum
How to print the IP which shows destination host unreachable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print the IP which shows destination host unreachable
#1
Hello Guys,
Here i am writing a script to ping a certain range of ip in python.I just did with which ip is pingable and which ip is not pingable,i just need to print which ip shows destination host unreachable also.How to do that?
print "Enter the start ip:"
save=raw_input()
print "Enter the end ip:"
save1=raw_input()
start=int(save.split('.')[-1])
end=int(save1.split('.')[-1])
b=save.rsplit('.', 1)[0]

def ip():
    import os
    for i in range(start,end):
        IP= str(b)+'.'+str(i)
        a = os.system("ping -n 1 " + IP)
        if a == 0:
            print IP, 'is pingable'
        else:
            print IP, "is not pingable"
ip()            
         
Output:
Enter the start ip: 172.30.36.90 Enter the end ip: 172.30.36.95 IP STATUS: 172.30.36.90 is pingable 172.30.36.91 is pingable 172.30.36.92 is not pingable 172.30.36.93 is pingable 172.30.36.94 is pingable
When i ping 172.30.36.91 in windows cmd it shows Destination host unreachable.
Output:
C:\Users\Meeran>ping 172.30.36.91 Pinging 172.30.36.91 with 32 bytes of data: Reply from 172.30.36.93: Destination host unreachable. Reply from 172.30.36.93: Destination host unreachable. Reply from 172.30.36.93: Destination host unreachable. Reply from 172.30.36.93: Destination host unreachable. Ping statistics for 172.30.36.91:     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
i need the output like this
Output:
IP STATUS: 172.30.36.90 is pingable 172.30.36.91 is  Destination host unreachable. 172.30.36.92 is not pingable 172.30.36.93 is pingable 172.30.36.94 is Destination host unreachable.
Reply


Messages In This Thread
How to print the IP which shows destination host unreachable - by MeeranRizvi - Jan-11-2017, 07:02 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020