473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

tcp traceroute

Hi,

I want to write a small tcp traceroute script. I works, but how
can I get the IP of the hop that send 'no route to host'?

Result:
python tmp/tcptraceroute.py a.b.c.d 80
ttl=01: (113, 'No route to host')
ttl=02: (113, 'No route to host')
ttl=03: (113, 'No route to host')
ttl=04: timed out
ttl=05: timed out
ttl=06: timed out
ttl=07: timed out
ttl=08: timed out
ttl=09: OK
#!/usr/bin/env python
# tcptraceroute.py
# This script is in the public domain

import os
import sys
import struct
import socket

def usage():
print '''Usage: %s host port
Tries to connect to host at TCP port with increasing TTL (Time to live).
''' % os.path.basename(sys.argv[0])

def main():
if not len(sys.argv)==3:
usage()
sys.exit(1)
ttl=1
host, port = sys.argv[1:]
port=int(port)
for ttl in range(1, 30):
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.IPPROTO_IP, socket.IP_TTL, struct.pack('I', ttl))
s.settimeout(2)
try:
s.connect((host, port))
except (socket.error, socket.timeout), err:
print 'ttl=%02d: %s' % (ttl, err)
s.close()
continue
except KeyboardInterrupt:
print 'ttl=%02d (KeyboardInterrupt)' % ttl
break
print 'ttl=%02d: OK' % (ttl)
break

if __name__=='__main__':
main()
Nov 28 '07 #1
0 1643

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: marvin | last post by:
Hi- if i want to send secure information to my sister: 1) generate a key on keyfocus on my local machine (not connected to the web using keyfocus webserver) 2) base64_encode encrypted data...
13
by: Bob Rivers | last post by:
Hi, I was doing a research looking for Java solutions that are able to do "ping". I found old messages (and not so old ones), telling that Java was not able to do that, because the API...
73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
3
by: Rainer Krauss | last post by:
I would like to code (just for learning) some band objects for Internet Explorer. To start with, i simply like to add a button to the Browser called "Trace". Pressing it should open a band like...
1
by: Heiko Besemann | last post by:
Dear group, I created an aspx page using System.Diagnostics.Process() to launch "tracert" from shell and redirect output to Response.Output which prints it as text/plain into my browsers window....
2
by: siva shankar | last post by:
Help!!! Help!!! Help how can i get the ip-address of the routers can any one guide me it should be done in asp.net
2
by: sm4rt | last post by:
hi I want help you in the "install JBuilder9" on liunx fedora how to install ? I make this # ./per_install.bin LAX_VM $x/bin Preparing to install... Extracting the JRE from the installer...
2
by: hutch75 | last post by:
Hi All - chasing down a means to initiate a traceroute, record results, and extract IP addresses in an (array?) Here's what I'm thinking about so far, wonder if anyone's been down this road before...
5
by: garks | last post by:
Is there any way to know the computer is connected to a router? I know using WebRequest is one of the method, but WebRequest need router's URL , username and password. I don't know those...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.