I am using libresolv library to create an application which takes DNS server names in command line arguments and query host names to this specific DNS server.
_res.nsaddr_list[0].sin_family = AF_INET;
_res.nsaddr_list[0].sin_addr.s_addr = inet_addr(argv[2]);
_res.nsaddr_list[0].sin_port = htons(NS_PORT);
_res.nscount = 1;
res_init ();
l = res_query(argv[1], ns_c_any, ns_t_a, nsbuf, sizeof(nsbuf));
This works for local DNS servers if used. But when I try to pass 8.8.8.8 (google nameserver) res_query always returns -1.
I searched something similar on net and found res_init loads /etc/resolv.conf. Which I do notwant. I want to override resolv.conf and tell resolver to use user entered name server to be used.(Which fails for google server)
Related
I want to know the IP of a public domain name like stackoverflow.com e.g. using my esp8266.
I know there is a method WiFi.hostByName("www.stackoverflow.com",IP);
But this does not allow me to specify a particular specified DNS like 8.8.8.8
And I don't want to connect my esp8266 by specifying a primary and secondary DNS, instead it will get these info automatically from the router.
I want this procedure to overcome an issue with my esp8266. So I need to get the IP from a specified DNS server.
I have seen this interesting library but it uses EthernetUDP which I shouldn't be dealing with.
I tried the following :
#include <Dns.h>
#include <ESP8266WiFi.h>
void setup() {
WiFi.begin("SSID", "password");
DNSClient dnClient;
IPAddress IPtofind;
const IPAddress DNS_IP( 8, 8, 8, 8 );
dnClient.begin( DNS_IP );
if(dnClient.getHostByName("stackoverflow.com", IPtofind) == 1) {
Serial.println(IPtofind);
}
else Serial.print(F("dns lookup failed"));
}
but the compiler complains about
static void EthernetClass::begin(uint8_t*, IPAddress, IPAddress, IPAddress, IPAddress)
and it has the right for that.
Do you have any simple solution ?
It really should be simple I feel !
The esp8266 core for Arduino doesn't have setDNS like the WiFi libraries from Arduino, even if it should have the same API.
To set the DNS server without static IP configuration to change the DNS obtained by DHCP, you could use the espconn_dns_setserver function of the underlying SDK.
After coping the URI from cloud.mongodb, I'm trying to connect via compass (1.15.1) on windows 10, but I'm getting this strange error:
No hostname or hostnames provided in connection string
This is what I've done in the process (as you may see, I've filled out the Hostname input):
1. Copied the URI:
2. Pasted inside compass:
3. Added my IP to white list
UPDATE:
After setting the SRV Record as true, the error has been changed to:
URI does not have hostname, domain name and tld
you have to first copy to clipboard the connection string and then go to the MongoDB Compass and create a new connection (Connect -> Connect to..). The software will automatically complete the fields with that you had copied.
I started it by removing 'http://' prefix from Host address.
First copy the link altas gives you .
It might be the case when you have "#" in your password field. It breaks you password and alter the url for the host.
For eg : if your password contains "#" replace it with %40
I solved my problem with this.
It might be problem from some users.
Hope it helps
I am working through a python pyramid tutorial, and I have been making as many notes as I can inside the files I am writing.
something strange happened, I'd like to know why.
I wrote the development.ini file like was done in the tutorial then added notes.
# we are using this file for configureation in development
# config our wsgi
[app:main]
# which entry point to use as the app
use = egg:mysite
# reloads when templates are changed, not to be used in production
pyramid.reload_templates = true
#which server to use
[server:main]
#get the main entry point from the waitress package
use = egg:waitress#main
host = 0.0.0.0
port = 6534
# this is a great way to remove code for the rest of our package
# more importantly this file is easy to tweak for launching our package in a different manner
running pserve development.ini chrome returns:
This site can’t be reached
0.0.0.0 refused to connect.
Search Google for 6543
ERR_CONNECTION_REFUSED
I remove the comments:
[app:main]
use = egg:mysite
pyramid.reload_templates = true
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6534
I receive the same error as before.
This site can’t be reached
0.0.0.0 refused to connect.
Search Google for 6543
ERR_CONNECTION_REFUSED
THEN I copy and paste code from the tutorials repo into development.ini:
[app:main]
use = egg:mysite
pyramid.reload_templates = true
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543
I am successfully able to reach localhost.
I am most interested to know, why this happened, how to avoid this problem, and if possible how to comment a development.ini file.
note:
I am using PyCharm as my ide
I am running this code on my local computer
ERR_CONNECTION_REFUSED means that the port you entered in Chrome's address bar does not align with the port number configuration in your .ini file. Look very carefully at your port numbers to make sure they align. You transposed the 4 and 3 in your original .ini (port = 6534), so I assume you tried to reach http://0.0.0.0:6543 in Chrome's address bar.
Bonus tip: PyCharm allows you to compare a single file's history on disk as well as version control. This helps reveal typographical errors. Right/CTRL-click on the file, Local History > Show History.
The shortest version of my question is that calling ServerManager.Binding.Remove seems to remove a binding from IIS, but still leave it in HTTP.sys or wherever SSL bindings are set and breaks layers of my code further down.
I'm running an Azure Cloud Service that needs to use SNI to support multiple hostnames using SSL. Effectively what I'm doing is in OnStart removing the default binding using ServerManager.Binding.Remove(binding) and adding my own bindings using ServerManager.Binding.Add(binding). So for example:
ServerManager serverManager = new ServerManager();
Site site = serverManager.Sites[0];
// Add my site bindings.
foreach (string host in listOfHostsToBind)
{
X509Certificate2 cert = LookupCertificate(host.sslThumbprint);
var binding = site.Bindings.Add(":443:" + host, cert.GetCertHash(), "My");
binding.SetAttributeValue("sslFlags", 1); //Set SNI flag
}
// Remove the default binding
var bindingsToRemove = new List<Binding>();
foreach (Binding binding in site.Bindings)
{
if (binding.Protocol == "https" && Convert.ToInt64(binding.Attributes["sslFlags"].Value) != 1)
{
bindingsToRemove.Add(binding);
}
}
foreach (Binding binding in bindingsToRemove)
{
site.Bindings.Remove(binding);
serverManager.CommitChanges();
}
serverManager.CommitChanges();
What ends up happening is that the default IP:Port binding is removed from the list of IIS bindings, but it still shows up in the list of SSL bindings when I call netsh http show sslcert.
So, for example, here's the output from calling Get-WebBinding in Powershell. Notice that the default IP:Port binding is not there:
protocol bindingInformation sslFlags
-------- ------------------ --------
http 10.20.30.40:80: 0
https :443:myfirstaddedhost.com 1
https :443:mysecondaddedhost.com 1
Looks good, but it still doesn't work, because if I run netsh http show sslcert I get the following:
IP:port : 10.20.30.40:443
Certificate Hash : xxx
Application ID : {00000000-0000-0000-0000-000000000000}
Certificate Store Name : MY
...
Hostname:port : myfirstaddedhost.com:443
Certificate Hash : xxx
Application ID : {4dc3e181-e14b-4a21-b022-59fc669b0914}
Certificate Store Name : My
...
Hostname:port : mysecondaddedhost.com:443
Certificate Hash : xxx
Application ID : {4dc3e181-e14b-4a21-b022-59fc669b0914}
Certificate Store Name : My
...
Why would the SSL Cert binding still be there if I successfully removed the binding from IIS using ServerManager?
Turns out that configuring the role for Remote Desktop from the Azure Portal was adding the binding. More specifically, updating the Certificate configuration for the role (which happens as part of RDP config) is causing it. This meant that it worked until I went in via RDP to check whether it was working at which point it would start to fail. Of course, genius that I am I was trying to be methodical and do things in the same order every time, which meant I was configuring remote desktop before actually attempting a request, so from my perspective it looked like it was failing from the beginning. It was only when I tried things in the opposite (running requests before configuring RDP) that it started to work.
You can use netsh http delete sslcert to delete the binding and it does not affect your ability to log in via RDP to that instance.
When you configure RDP it calls the RoleEnvironment.Changing and RoleEnvironment.Changed events, but unfortunately when those events are called the binding has not been created yet, so there's not an obvious place where you could use netsh http delete sslcert to delete the binding in code.
I don't know that this is an "answer" exactly. It means I still have an issue where configuring an Azure Instance for RDP or changing the cert configuration breaks my SNI bindings. For my organization this is OK because there are only a couple people with enough permissions to configure RDP and they can be trained to explicitly delete the new binding if they need to use RDP. I'll follow up here if I figure out a way to prevent this altogether.
I'm reading out the mime types from IIS's MimeMap using the command
_mimeTypes = new Dictionary<string, string>();
//load from iis store.
DirectoryEntry Path = new DirectoryEntry("IIS://localhost/MimeMap");
PropertyValueCollection PropValues = Path.Properties["MimeMap"];
IISOle.MimeMap MimeTypeObj;
foreach (var item in PropValues)
{
// IISOle -> Add reference to Active DS IIS Namespace provider
MimeTypeObj = (IISOle.MimeMap)item;
_mimeTypes.Add(MimeTypeObj.Extension, MimeTypeObj.MimeType);
}
Do I need replace the localhost part when I deploy it to my live server? If not, why not and what are the implications of not doing so.
Cheers
It should not be an issue to leave the host as 'localhost'.
After all, you want to get the MimeMap of the machine your app is running on, correct?
A possible complication that I can forsee is that if you are using a third party as a host. They can do anything they want with host headers and it may be possible that localhost is not available for whatever reason.
But you should simply give it a shot and adjust if necessary.
If you leave it like 'Localhost', you will have to run this script directly on the server.
If you change it to fetch the machine name directly, you can think of running this script remotely as well.