5 ms·
Show HN: Rust Library to check your Internet connectivity
- sara7262 7y agoSee the video of most dangerous bird and how he killed owner https://howto105.blogspot.com/2019/04/most-dangerous-bird-killed-owner-in-usa.html https://howto105.blogspot.com/2019/04/most-dangerous-bird-ki... Funny dog driving own car See his video on link below http://bit.ly/2WdSKpA http://bit.ly/2WdSKpA Cute dog going for school like human baby see his cute video I am sure you can't stop laugh http://bit.ly/2Wq6Ynr http://bit.ly/2Wq6Ynr United nation recently showed the real face of india See what they said in report After knowing this I am sure you will hate them if you have soft heart https://youtu.be/oUskNtdWeIY https://youtu.be/oUskNtdWeIY Best way to get rid from face moles with the help of home remedies its easy and simple way You don't need to waste money for this https://zoomtips.blogspot.com/2019/05/easily-get-rid-from-face-moles-with.html https://zoomtips.blogspot.com/2019/05/easily-get-rid-from-fa... Girl made a strange world record even you can't believe this see her video on link below http://bit.ly/2ErUDEW http://bit.ly/2ErUDEW Trump is useful now lol See in video what China did with trump http://bit.ly/2VPVZis http://bit.ly/2VPVZis Lose weight without exercise Now weight losing is not hard job just follow this simple method https://rebrand.ly/loss-weight https://rebrand.ly/loss-weight Now don't worry about dry hair or dryness on scalp Just follow this simple methods which you can make with simple home remedies and get rid from hair dryness https://zoomtips.blogspot.com/2019/05/treatment-for-dry-hair-and-scalp.html https://zoomtips.blogspot.com/2019/05/treatment-for-dry-hair... This video is important for Facebook users must watch this otherwise you will loss your Facebook id https://rebrand.ly/Facebook-id-danger https://rebrand.ly/Facebook-id-danger
- OskarS 7y agoSo... the test is "can I connect to either the website icanhazip.com or OpenDNS". With the IPv4 addresses of both burned into the code. So this depends on two external servers never going down and not ever changing IP addresses, one of which is pretty sketchy ("icanhazip.com", seriously?), and it wouldn't work AT ALL in an IPv6-only environment (which I grant is rather unlikely at the moment, but might not be in the future). I like Rust a lot, but micro-packages like these are giving me real bad "left-pad" vibes.
- sushibowl 7y agoAm I currently connected to the internet isn't really a question which has a meaningful answer in the first place. The internet is not a monolithic object you can connect to, and achieving a connection to any endpoint doesn't particularly guarantee your connection to anything else. The actually meaningful question you almost always want answered instead of "am I online?" is "will I be able to connect to X host?" The obvious check is to try to connect to that host.
- OskarS 7y agoYeah, I totally agree, but you can sort-of imagine this being useful as like an indicator light in your OS or something. But don't use this library for that. Don't use this library for anything.
- jesusprubio 7y agoObviously, you're right. And I can imagine any developer can imagine the same thing :). But I couldn't find a better way to check if I am online than making a request to any server. In fact, I'm using two over different protocols just in case.
- oconnor663 7y agoOne area for improvement: Default to a set of domains to check rather than just one, for example google.com, facebook.com, baidu.com. Check them all in parallel, and return success as soon as you get a good answer from 2 out of 3. This avoids falsely reporting "offline" when one host happens to be down, and it avoids slowing down the check when one host happens to be slow. Probably use `mio` to orchestrate this, to avoid the overhead of threads. (Note that this is similar to how musl libc implements DNS.) Another area: Think about what should be reported in a country like China. For example, facebook.com is blocked. If China blocks google.com tomorrow, does that mean that every computer in China is offline? Probably not. On the one hand, this isn't something that a library can give a one-size-fits all answer for. On the other hand, since China has the most internet users of any country in the world, this is probably something that the design of the library should consider and offer documentation and best practices for. Another area: Many GUI apps expect to make ongoing connections, e.g. chat apps that are always listening for messages. These apps need to persistently check the status of the network in the background, and many would be willing to dedicate a background thread to this library if it helped with some of the details of that, like 1) detecting hardware-level state changes, like WiFi coming and going, to prompt an immediate re-check, 2) checking in a rapid loop after a network change, but backing off to a lower background rate when the network is stable, 3) "de-bouncing" network events in case the network seems to be coming and going multiple times a second, so that UIs responding to those events don't flicker. Higher level: This is a common problem. Find other libraries that have solved this problem before, compare the different ways they've solved it, and document the tradeoffs. I appreciate that I'm suggesting that you do a lot of work, but if you intend for production applications to use this code then it's very important work.
- dsl 7y agoThis library is dangerous and should not be used. It contains hardcoded values that could result in the library not working as intended, or unintentional DoS attacks against innocent third parties if it were implemented in a widely distributed piece of software.
- ay 7y agoIn general “checking whether the connectivity to internet exists” is an idea that may create a massive pain down the road when implemented, because the heuristics used are not equal to actual connectivity, thus will break one day. Just attempt to perform the operation you want, and if it fails, give the feedback to the user that it failed. Why does it have to be more complicated than that ? (It is not a rhetorical question)
- spuz 7y agoWay back in the dial-up days, I wrote a program to measure the periods of time that a user was online and the corresponding phone call charges which varied depending on the time of day. This meant I had to know to the second whether or not the user was 'online'. Since the days of per-minute charges for internet are long gone, I find it hard to imagine other reasons you would need to know if the user is online rather than able to access a specific server.
- jesusprubio 7y agoIt's only my first crate I made to learn about the environment. But I truly believe in this micro modules way of building things. If it reduces complexity it's welcome. :)
- jesusprubio 7y agoAgree, answered in other comments but the idea is I truly believe in this micro modules way of building things. If it reduces complexity it's welcome. :)
- d33 7y agoIt's pretty easy to measure how many projects your library is tied to and scale the service up. Yes, ideally it would have a large pool of servers to test against, but I think it's a good idea to abstract the problem away and then work on it. EDIT: it looks like I'm getting downvoted for this opinion - could any of the downvoters also reply as to why it's a bad idea?
- twic 7y agoI don't know of any IP addresses that it's safe to hardcode in software like this. However, there are hostnames that it's safe to hardcode: the DNS root servers, a.root-servers.net etc. If you have working hostname resolution, even if intermittently, you could in principle resolve those, and then check connectivity. However, it's probably not a good idea to use these crucial public resources for something so pointless! Interestingly, all of the root servers except G also have a companion website, ${letter}.root-servers.org, which could perhaps be used for an HTTP connectivity check. Those websites aren't hosted on the same machines as the nameservers.
- jesusprubio 7y agoThank you! Very interesting thoughts, adding them to the repo here:https://github.com/jesusprubio/online/issues/7 https://github.com/jesusprubio/online/issues/7 Please feel free to contribute ;).
- georgyo 7y agoThe universal consensus after anyone looking at the code is that they should not use it. What I don't understand is why and who are they people who are up voting this and keeping it on the front page. Do people just see rust, and then up vote? If so, while rust may be good, blind voting everything written in rust is good will cause distrust later.
- maltalex 7y agoI don't think there's a reason to use TCP for this unless you want to check for TCP connectivity specifically. Just do a DNS lookup against a list of well-known public DNS servers.
- deleted 7y ago[deleted]
- oconnor663 7y agoOne reason not to do DNS exclusively is that many networks allow DNS requests (and intercept them) but block HTTP requests.
- jesusprubio 7y agoBTW, there're parts of DNS over TCP.