What is the simplest way to get IP address of a domain? - dns

We're developing an embedded application, running on a standalone GPRS connected device (no operating system there). We are trying to get an IP address of domain name. I think that we should use some public DNS service, like Google DNS (8.8.8.8). The question is - what is the simplest request we should send to 8.8.8.8:53 in order to receive IP address of our domain?
Again, we can't use libresolve or any other similar libraries. We will make a simple TCP connection to port 53 of Google DNS, and will format our request ourselves.
I tried to understand RFC1053 myself, but failed. Too many words :)

I'm not a DNS expert in any way, but I thought that DNS generally use UDP rather than TCP?
Either way, here's a link to a page that describes the communication using less words that might be easier to understand than the RFC itself.
Also, even if you can't use the libresolve library itself, can't you look at an open source version of that library and use the code from one of those (assuming that the license is compatible with your work). Here's one from Apple that I found via google.

Related

Why my web traffic is redirected via IP 10.0.0.11 address on my Mac?

I know nothing about networking. so I need serious help here. I was on a Zoom call with my mentor and we were talking about the difference between HTTP, HTTP1, and HTTP2. Then he noticed that even websites which are supposed to use HTTP1 all of them were showing as if they are using HTTP2.
He mentioned possible problems are:
I'm using VPN
or my web traffic is redirected via a Proxy server. (which I'm not since I work from home via my wifi provided to me via fiber optic cable)
I suspect that there is some kind of proxy malware on my laptop. Can anybody tell me how can i detect any possible malware and find out in general what is wrong? (if anything is wrong at all)
Thanks in advance.
The range from 10.0.0.0 to 10.255.255.255 is one of the private IP Ranges and as you are using wifi its normally assigned by your wifi-router/accesspoint to your computer using dhcp.
But seriously, a professor who thinks he is capable talking about http(x) should know the very basics of the protocol stack. If he doesn't know such simple things, you better get someone better.

How do I use SSDP?

I need a way for my application to find someone with the same application on a local network.
But can't find the docs to use a protocol like SSPD. It says its UDP on port 1900 and the ip 239.255.255.250.
It also says it can use NOTIFY and M-SEARCH.
But that is it. I've hit a wall. And I need some guidence.
OVERVIEW
Trying to make my apps automatically find each other and exchange ip/names on a local network so they can talk to each other p2p-style without a connection broker.
The UPnP Device Architecture reference contains the de-facto SSDP reference: it's very similar to the IETF spec and has dozens of well tested implementations already. Chapter 1 contains everything needed to implement SSDP, assuming you know how to send and receive multicast and unicast UDP messages.
My advice on implementing SSDP: Don't. It may look simple but there are a lot of gotchas on the way. Find a library or service that does SSDP for you. If you are on linux I suggest GSSDP (reference, code) (but I'm a bit biased having worked on it). I would assume other platforms have similar libraries.

How to access Internet connected Debian Linux computer through SSH? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have a BeagleBone Black that is running Debian Wheezy. I want to be able to SSH into it over the internet as long as it is connected to the Internet. I want to be able to type in an URL and be able to access it or deploy software on it.
Many other posts showed how one has to configure the router to forward the port and such. However, I want to be able to take this Beaglebone anywhere, maybe even at a coffee shop with Wifi, and I can quickly access it from another computer through the Internet.
I am wondering what is the best approach to do this. I have my own domain name (provider is Namecheap.com), and I won't mind actually paying for some web hosting services if the solution requires that.
To sum it up, I want to be able to SSH into a Debian Linux system via a domain name without any configuration with the network hardware. I want to be able to quickly set it up and access it as long as the system has internet access. How can this be done?
You need to use a "dynamic dns service", since (most likely) your home ip address is not static. it changes with time, which is why it makes sense to use a domain name. However you can not use a normal dns service, since that updates far too slowly.
You need to configure that dynamic dns service such that it points to the current public ip address of your home router. Typically that is done by a trigger that submits the new ip address as soon as the internet connection has been established. So this has to be done from within your home network, typically by a feature of your router (if offered). Alternatively you can use some utility installed on your boards system that is able to detect its public ip address and when that changes. There are some such utilities in the standard repositories. You can not simply publish your ip every minute or so. It has to be event driven (on connect), or you will probably be blocked by the dynamic dns service.
Then indeed you have to configure port forwarding on your home router. The rule has to forward all incoming requests to a specific port to your boards port 22. Note: do not use port 22 on the outside, so do not forward port 22 to port 22. This works, but you will see constant brute force hacking attacks against your system. Just use something like 50022 or whatever (on the outside!).
That should be all.
I take from your comment that you also want to be able to take that board wherever you go and just use any connection wherever. Such thing is possible, but much more complex. For certain you do need some additional server you have control over. That server has to play relay and forward your requests to your board which establishes an ssh tunnel between that server and itself as soon as it goes online. So you definitely do need some fixed point somewhere. Such a server is no rocket science. You can rent a virtual one for 3-5 Euros a month these days and do with it whatever you want.
The idea here is that your board contacts that server and establishes an ssh tunnel pointing back to its own port 22. Now you can contact the tunnel which is open at the server and your packages will be forwarded through the tunnel to your board. That works, it is a bit slower than otherwise.
In that case you do not need a dynamic dns service, since such a virtual server typically comes with a fixed ip address. So you can simply resolve your domain to that server of yours.
Question in this case is why to do that. Since you already have a comfortable server at your hand, so what is the board for? The only motivation I can think of is to be able to do illegal downloads or hacking attempts in the foreign environment... Which is not an issue in general. Networks are there to be explored. But you clearly should think thrice when you leave the legal ground. Especially about whom you might cause massive troubles :-)
Oh, you could also combine this approach with using your home router instead of a separate server in the internet. Your board can access your home network using the dynamic dns service, contact some system inside your home network which acts just like the rented server described above.
Taking the additional information from that next comment you gave also this might be worth a try, though I am not sure if that will work. You will have to give it a try:
If everyone meant to access the board is within the same local network, then you might get along without the need for port forwarding. You could try to use one of the mentioned dynamic dns utilities to publish your network internal ip address to the dns service. If they accept and publish that address, then everyone should be able to directly access your board inside the local network (so no via the internet), but by using your domain name. I never tried such thing. I could imagine that dns service providers block such thing. But then again, they might not. So it might be worth a try, since it would be a very simple and elegant solution. Also I am not that sure if all systems will accept such an internal address from a dns authority. As said: you will have to try this.
There certainly are more theoretical possibilities, but those certainly are much more complex. If you stay near your board you certainly can also use things like bluetooth or similar. You could bundle a cheap and broken smartphone and use it as a modem, that way the board can act just like the home router above. Certainly you have the option of a wifi ad-hock network connection, but I doubt that is what you are looking for.
One thing I would definitely not do is use a third party service provider specialized in such things. Something like TeamViewer or similar. I consider these a serious and obvious security thread, despite what they claim themselves. You definitely can never trust a closed source or internet only service, since there is simply no way for you do really check what they do. So do not fall for that apparently simple and comfortable solution!

Webify embedded linux-based controller through cellular network

Need a basic direction in the following project.
There is a linux based controller doing some industrial control stuff.
The box is equipped with cellular modem and is capable to get online through cellular carrier. Cellular communication is used because controller is mostly installed where no cables or short range radio is available. Places where sun don't normally shine :)
The task is to allow internet clients to connect directly to the box for some basic control/monitoring stuff. The problem is connectivity - how clients will discover the box? - I'd like to have the box act as a server (if possible). Assuming that cellular carrier allows the box to get online doesn't necessarily mean that the box will get public IP so that anyone would be able to get connected. To my understanding the cellular network acts as a gateway from those who are working inside of it, and reaching someone in that network from outside isn't possible. Am I wrong? We are looking for a generic solution, not a solution around particular cellular provider. The controller is installed in different countries, we need to find the standard way to "webify" it.
The software (and hardware) in the box is ours, we can basically do anything, but I am looking for the right way to do it in order to avoid surprises with different providers later. BTW, the solution doesn't necessarily have to be technical, may be it's possible to buy a permanent IP's per box, or setup VPNs.. Which way should I dig to? What questions to ask?
Your ideas are welcome!
Your summary of the problem is basically correct. I've implemented several systems that do this, and the odds of success are good.
The way you tackle this will depend on the number of remote units you expect a single user to interact with. If each user will handle only one or two devices, it's plausible to implement the web server on the remote device. If each user handles many devices, consider centralising as much administration as possible. I've implemented this using Zenoss for data logging, and a custom control server.
If the web server sits on the remote device, you can either buy a SIM with a static IP, or use a proxy server. I recommend setting up a proxy server unless the number of devices is very small.
There are three options for SIMs:
Static IP with an address on the public Internet will be expensive, and negotiating the deal with each provider in each country will be irksome. No proxy server is required.
Private APN SIMs will give you the option of a static address, but in a private address range. Negotiation with the mobile network is still required, and you will require a proxy server to sit between the public Internet and the private address range,
Standard data SIMs will connect to the Internet through NAT. You can use these to host your service by opening a VPN connection (we used openvpn) to your server. You can now reach the devices directly by connecting to the same VPN, or through a proxy server.
If you use openvpn, here are some more tips:
Give each unit a public serial number, and a private key. Store these in the firmware of the unit, and in a central database. Put the public serial number on the outside of the unit. You can use an openvpn login script to ensure that a particular unit always appears at the correct IP address, which keeps the proxy configuration static.
You can control openvpn's bandwidth usage by adjusting its keepalive behaviour, and how often it renegotiates. Measure and tune this before a large deployment.
The NAT timeouts in the mobile networks are generally between 5 and 15 minutes. The device must send a packet to the server often enough to keep NAT alive.
Cheap SIM deals may be web only with limited ports.
Other tips:
GPRS modem firmware can (rarely) crash internally. If your hardware supports it, provide software with the ability to power cycle the modem.
Test your box in areas with poor coverage in your own country before you send out international shipments.
This is a typical problem with "mobile agent" appearing in different places or using different providers (in this case just one provider, but it's almost the same). Usually it's solved using some kind of home agent - a server that the mobile connects to and gives details about how to reach it or if it can't be reached directly then the home agent acts as a proxy.
Client always contact the home agent first and then if it is possible they contact the mobile or if it's not they use the server as a proxy.
In some cases dynamic dns might be sufficient in other you need real proxy/ façade.
There's a good book: Andrew S. Tanenbaum & Maarten van Steen :"Distributed Systems: Principles and Paradigms"
You can ask cellular provider to give you a SIM card with internet access and fixed IP address. Then you can host any server you like. Do not forget that you are dealing with limited bandwidth.

Doing ARP and Inverse ARP on Linux 2.6.21 (glibc 2.3.5)

I need to store persistent reference to third party device on an arbitrary IP network where the IP address of the devices may be static or randomly assigned by DHCP. I don't control the devices on the network and I can't rely on DNS and other ad-hoc networking protocols existing or working with the devices.
So I have been instructed to investigate using hardware addresses and ARP. This will work but I don't want to duplicate code. The kernel must manage an ARP table. On Windows you can access it using GetIpNetTable etc.
I am hoping there is an API to answer these two questions:
How do I translate from IP to MAC address? (ARP)
How do I translate from MAC to IP address? (InARP)
If not then I may have to do it more manually:
How do I read the kernel's ARP table?
How do I add an entry if I have the determined a mapping myself?
/proc/net/arp
K
ARP tables tend to be fairly local and short-lived. If you examine the protocol, the real MAC addresses are generally only provided when the given IP address is in the local subnet.
Otherwise, the packet is forwarded to the local router, which is then responsible for forwarding it.
If you do "arp -g" on Windows or "arp -a" on UNIX, you'll see the table, but I don't think it will do you any good, due to the reasons mentioned above. That command and
That's really what DNS is for but, as you say, it may not be an option for you.
You may well have to write your own 'ARP' database at your application level.
As for ARP:
You could use system("/usr/bin/arp -option_of_choice"); and parse the output, but that's an ugly hack. -- Not my recommendation.
Take a look at /usr/include/linux/sockios.h -- At the SIOCGARP, SIOCDARP, and SIOCSARP details. Those are ioctls that you can perform to manage the ARP table on linux. Of course, you'll have to perform these ioctls on a socket fd.
Here's some examples: SIOCGARP examples
I'm sure you can find many other examples in several other languages as well. As I'm assuming that you're using C.
As for RARP:
A quote from the linux rarp manpage:
" This program is obsolete. From version 2.3, the Linux kernel no longer
contains RARP support. For a replacement RARP daemon, see ftp://ftp.demen-
tia.org/pub/net-tools"
So you'll have to install rarpd on the target system.

Resources