Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,023 members, 7,953,064 topics. Date: Thursday, 19 September 2024 at 10:09 AM |
Nairaland Forum / Science/Technology / Programming / How Can I Get IP Of A Specific Hop For Traceroute In Python (1289 Views)
Tutorial: Object Oriented Programming Paradigm For Beginners in Python / Who Wants To Learn Programming In Python Easily Without Stress? READ THIS / What No One Tells You About Coding In Python: Eye-opening! (2) (3) (4)
How Can I Get IP Of A Specific Hop For Traceroute In Python by Nobody: 9:41am On Aug 20, 2017 |
https://www.friendosphere.com/38/how-can-i-get-ip-of-a-specific-hop-for-traceroute-in-python addr = socket.gethostbyname('dalitstan.org') target = [addr] result, unans = traceroute(target,maxttl=32) I am doing this and getting the below output. Is there some way here to get the IP of specific hop in a variable. And also why some hop number are missing in the traceroute result? |
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by Fulaman198(m): 1:06pm On Aug 20, 2017 |
DanielTheGeek: I'm not too familiar with Python, but couldn't you iterate through the hops and return the IP address at a specific index? |
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by Nobody: 3:55pm On Aug 20, 2017 |
Fulaman198: Returning at a specific index is the part that's not working for me. I only want it for a single hop. Check the link in the OP for the rest of the code. I don't need iteration...this result.get_trace() doesn't just seem to work as desired. |
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by Fulaman198(m): 10:27pm On Aug 20, 2017 |
Can you try adding comments to your code, as aforementioned, I am not too familiar with Python (yet, I will have to learn it soon though for Data Science projects). From what I can interpret from the below, this is what you are doing: addr = socket.gethostbyname('dalitstan.org') <------- In this line, you have a variable datatype created known as addr using a socket interface functions method gethostbyname to call a DNS like function to convert dalitstan.org to an IP address (more specifically an IPv4 address). target = [addr] <-----Here, you are declaring an array of type address (I think this should go before declaring addr = socket.gethostbyname('dalitstan.org') result, unans = traceroute(target,maxttl=32) <--------------------- Here you are creating I guess what you would love to output later, a call to a traceroute function with the array of address, and setting the maximum Time to live to 32). Again, I'm not too familiar with Python, I will be in a few months time, but which file is the cens2.py file? Apparently, there is a bug of some sort on line 16 in that python source code. When I attempt an nslookup on 185.53.178.6 it fails, and ICMP echo request (ping) fails on it as well. I see this error: TypeError: 'bool' object has no attribute '__getitem__' I know that in languages like C/C++ and Java, a boolean often needs to return true or false, or have some value that returns true or false. Are you posting your entire code? thanks! |
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by Nobody: 12:14am On Aug 21, 2017 |
Fulaman198: That's most of the code....except i was using scapy, was actually testing something, planned on using this in a different environment but had to test first. At the moment i think result.get_trace()['185.53.178.6'][7] ('203.50.6.93', False) or >>> result.get_trace()['185.53.178.6'][7][0] '203.50.6.93' >>> something = result.get_trace()['185.53.178.6'][7][0] >>> something '203.50.6.93' seems to work... |
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by Nobody: 12:24am On Aug 21, 2017 |
I think this explained better https://blogs.oracle.com/ksplice/learning-by-doing:-writing-your-own-traceroute-in-8-easy-steps and now i am using trace_route differently. If i may ask, just curious? Do you have any experience with system administration? |
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by ozq10: 2:23am On Aug 21, 2017 |
send your names to the number to be part of it its free.
|
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by segbolon: 3:15am On Aug 21, 2017 |
You figured it out, but sometimes you might not need to write a program. trace route www.google.com | head -6 | tail -1 | cut -d" " -f5 Where 6 is N+1, where N is the IP of the hop I want to see. |
Re: How Can I Get IP Of A Specific Hop For Traceroute In Python by Nobody: 7:39pm On Aug 21, 2017 |
segbolon: Thanks for the input, but on an automated system or analysis application it would be better to have it implemented dynamically. |
(1) (Reply)
Matrix Issues (formula)..please Help Resolve / I Need Help On Laravel With Voyager / PLEASE Help A Beginner
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23 |