How to retrieve Connection-Specific DNS Suffix for Interface in Go? - windows

I am on a windows machine and programming in Go. When I do an ipconfig I am able to see my machine's interfaces.
Whenever I execute net.InterfaceAddrs() I get a bunch of IP addresses, and I know which one is the one I am looking for, but I want to be able to tell if those addresses belong to my domain. In the output of ipconfig I can tell this by reading the Connection-Specific DNS Suffix entry which has my "company.com" listed.
Any ideas?

See: similar question
try net.LookupAddr for each IP you get from net.InterfaceAddrs
assuming they reverse back correctly, they should end in your domain name.

Related

Win32: Can GetIpNetTable2() be used to return a list of all computers on the network?

I'm not sure what GetIpNetTable2() actually does internally? Can this be used in lieu of scanning each IP in a subnet, either sending ICMP Ping packet or requesting ARP? Is it reliable or will it only have a list of IP addresses the local computer has talked with?
Overall, what is the best way to find a list of all computers IP addresses available on the network via a Windows application?
TIA!

Why IP of nslookup and ping is not the same

I have a question I try to do a ping in the cmd like this: ping google.com, so it gives me an IP address A. But after, I want to do an nslookup to google.com It gives me an IP address B. Why ? My question is why the IP are not the same from the same website.
The answer is probably round-robin DNS. DNS allow you to specify multiple values for the same record, and the client library will determine with one to use (some use the first, some use the last, some use a random one, and some iterate through them).
Alternatively, the DNS server may be returning different values to the same query - either to do load balancing behind the scenes, or to send you to the geographically closest server.
I just resolved google.com from two separate computers and got two different answers:
host-a5$ dig +short google.com
216.58.204.14
host-b4$ dig +short google.com
172.217.23.14
This shows that the google DNS servers are returning different answers for the same query, most likely for load balancing and/or geo-centric reasons.
Here are 3 reasons:
ping might be getting an address from hosts file (nslookup doesn't)
ping might be getting a cached address (nslookup doesn't). Use ipconfig /flushdns to empty the cache.
the same host may have more than one addresses registered in the DNS

How do I find the local address on my mac so that I can scp?

I am on another computer, but I want to scp some files over to my macbook pro.
The command for this is:
scp -rp filename.txt user#path
How do I find the address/path of my mac? I tried
ifconfig
on my mac and a lot of descriptions popped up, including several numbers that could be IP addresses. However, I don't know how to interpret the data. Help?
The output of ifconfig gives the different interfaces your computer has. You might find several ip addresses, depending if you have both wired and/or wireless connections and/or other types.
The interfaces are listed like enX (en1, en2.. etc) depending on the number of interfaces you got.
For ipv4 address, look at the "inet:" part, usually something like 192.x.x.x., 83.x.x.x or something similar.
As an example,
ifconfig | grep inet
will result in the different inet(ipv4) addresses in your computer, for the different interfaces.
You were on the right track. When you use ifconfig on the far left you'll see a column with items like hi,lo,eth0,eth1,etc... These are the interfaces. Usually, the main interface is going to be eth0. Next to this should be a line which begins with inet addr:. The IP after that is your IP address. Use that to connect to that PC.

What is the source of proxy list ip addresses

There are websites that provide proxy lists like
http://hidemyass.com/ or http://letushide.com/ and Im sure there are a lot more, so the question is from where they take that ip addresses ?
If I make a search by them it shows some company or website/domain, and I do not think that company/website would allow to use their ip address, Or I am getting it wrong ? so how it is done ?
The second question is: is that possible that someone can use my website's IP address as a proxy to make a query. And if the answer is positive, can I prevent that somehow? Im on a shared hosting.
Thanks

How do you find out which NIC is connected to the internet?

Consider the following setup:
A windows PC with a LAN interface and a WiFi interface (the standard for any new laptop). Each of the interfaces might be connected or disconnected from a network. I need a way to determine which one of the adapters is the one connected to the internet - specifically, in case they are both connected to different networks, one with connection to the internet and one without.
My current solution involves using IPHelper's "GetBestInterface" function and supplying it with the IP address "0.0.0.0".
Do you have any other solutions you might suggest to this problem?
Following some of the answers, let me elaborate:
I need this because I have a product that has to choose which adapter to bind to. I have no way of controlling the setup of the network or the host where the product will run and so I need a solution that is as robust as possible, with as few assumptions as possible.
I need to do this in code, since this is part of a product.
#Chris Upchurch: This makes me dependent on google.com being up (usually not a problem) and on any personal firewall that might be installed to allow pinging.
#Till: Like Steve Moon said, relying on the adapter's address is kind of risky because you make a lot of assumptions on the internal network setup.
#Steve Moon: Looking at the routing table sounds like a good idea, but instead of applying the routing logic myself, I am trying to use "GetBestInterface" as described above. I believe what it should do is exactly what you outlined in your answer, but I am not really sure. The reason I'm reluctant to implement my own "routing logic" is that there's a better chance that I'll get it wrong than if I use a library/API written and tested by more "hard-core" network people.
Technically, there is no "connected to the Internet". The real question is, which interface is routeable to a desired address. Right now, you're querying for the "default route" - the one that applies if no specific route to destination exists. But, you're ignoring any specific routes.
Fortunately, for 99.9% of home users, that'll do the trick. They're not likely to have much of a routing table, and GetBestInterface will automatically prefer wired over wireless - so you should be good. Throw in an override option for the .1% of cases you screw up, and call it a day.
But, for corporate use, you should be using GetBestInterface for a specific destination - otherwise, you'll have issues if someone is on the same LAN as your destination (which means you should take the "internal" interface, not the "external") or has a specific route to your destination (my internal network could peer with your destination's network, for instance).
Then again, I'm not sure what you plan to do with this adapter "connected to the Internet", so it might not be a big deal.
Apparently, in Vista there are new interfaces that enable querying for internet connectivity and more. Take a look at the NLM Interfaces and specifically at INetworkConnection - you can specifically query if the network connection has internet connectivity using the GetConnectivity method.
See also: Network Awareness on Windows Vista
Unfortunately, this is only available on Vista, so for XP I'd have to keep my original heuristic.
I'd look at the routing table. Whichever NIC has an 0.0.0.0 route AND is enabled AND has the lowest metric, is the nic that's currently sending packets to the internet.
So in my case, the top one is the 'internet nic'.
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.0.10 10.0.0.51 20
0.0.0.0 0.0.0.0 10.0.0.10 10.0.0.50 25
(much other stuff deleted)
Another alternative is to ping or GetBestInterface 4.2.2.2 - this is an old and venerable DNS server, currently held by GTEI; formerly by Sprint if I remember right.
Start > Run > cmd.exe (this works in XP and Vista): ipconfig /all
This displays all info about the interfaces in your computer. The "public" facing interface should have a public IP address. For starters, it should not be 192.168.x.x or 10.x.x.x :)
running traceroute to some public site will show you. Of course, there may be more than one interface that would get you there.
Look at the routing table? Generally, unless you're routing between the networks in windows (which is possible, but unusual for a client computer these days) the interface that holds the default route is going to have the Internet connection.
Your question didn't detail why or what you're doing this with so I can't provide any specifics. The command line tool "route" may be of some help, but there are probably libraries for whatever programming language you're using to look at the routing table.
You can't rely on the IP address of the interface (e.g., assuming an RFC-1918 address [192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8] isn't the internet) since most sites have some kind of NATed firewall or proxy setup and the "internet" interface is really on a "private" lan that gets you out to the Internet.
UPDATE: Based on your further information, it sounds like you have a decent solution. I'm not so sure about the choice of 0.0.0.0 since that's a boundary case for IP address -- might be OK on your particular mix of platform/language. Sounds (from the API description) like you could just specify an address, so why not some address known to be on the Internet, e.g. the IP address of your web site, or something more random like 65.66.67.68? Just make sure not to pick one of the rfc-1918 addresses, or the localhost range (127.0.0.0/8), or multicast, any other reserved range, and any address that resolves to a .mil or .gov (while it doesn't sound like getbestinterface sends any traffic, it would suck to find out by having the feds break your door down... :)
Looking at the network point of view, either could be routing to the "internet" at any time. If things like spanning tree protocol are enabled on a switch then you may find that what may have been the routing card to begin with may not be anymore.
Ping google.com though each NIC.

Resources