I'm working on a network analysis tool (academic research), and I would like to find out what DNS is used on the machine the software is running on. I'm not a network admin, and I'm wondering: what's the easiest way to find that out; across platforms (that is, on each Linux, Mac and Windows), and preferably using something that's accessible in Python?

Usually, systems seem to conveniently hide this stuff from the user -- I can set a fixed DNS, or I can use my router's settings via DHCP, or ... I'm sure there are other systems too (LDAP?). So just looking at resolv.conf may not always lead to the right answer -- or does it?

Many thanks!


Question: Problem with Compile and Flatten
Answer: It looks like the problem you are running in to is because list is a ragged array, which is not allowed.  Replace {j,i,r-1} with {j,r-1} and you get a function that compiles and runs (despite the fact that it doesn't give you the desired output).

One way to get your desired output is to create a regular array with some criterion that can be selected for removal afterwards.  Note I specifically avoid the use of pattern since pattern matching is not allowed in Compiled functions.

This seems to work:

f = Compile[{{r, _Integer}}, 
  Module[{list, i = 0, j}, 
   list = Table[{i, If[j &lt; i, -1, j]}, {i, 0, r - 1}, {j, 0, r - 1}];
   Select[Flatten[list, 1], #[[2]] =!= -1 &amp;]]]