Python Forum
python 3 dns lookup private domain
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python 3 dns lookup private domain
#2
(Sep-19-2020, 01:52 PM)didact Wrote: When I ssh to them, I'm assuming there is a DNS lookup done, and I'm guided to the correct IP address in the background.

While that may be true, ssh has other things it can do. You can create host aliases that would prevent the need for a DNS lookup. You could associate an IP with a name in the config. You could validate if the DNS is working on the local host with dig or nslookup just to make sure it's valid in the first place.

Quote:I've written a program that logs into our cisco and ciena equipment and runs some commands - but it only works if I supply the IP address - not the device name. I'd like to write some code that does a quick lookup and then proceeds with the rest of my program.

Your other equipment may have different DNS configurations than your workstation. So resolution may happen differently.

Try this to use the local resolver on your machine:
import socket

def name2ip(hostname):
    try:
        ip = socket.gethostbyname(hostname)
        return ip
    except socket.gaierror:
        return None


for name in ["www.google.com", "www.python.org", "no.such.name"]:
    print(f"{name} resolves to {name2ip(name)}")
Output:
www.google.com resolves to 216.58.195.68 www.python.org resolves to 151.101.40.223 no.such.name resolves to None
Reply


Messages In This Thread
python 3 dns lookup private domain - by didact - Sep-19-2020, 01:52 PM
RE: python 3 dns lookup private domain - by bowlofred - Sep-19-2020, 06:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Peaks in time domain frohr 0 500 Jul-06-2023, 02:57 AM
Last Post: frohr
  Lint and private var names PatM 1 727 Dec-15-2022, 05:08 PM
Last Post: deanhystad
  2-dataframe, datetime lookup problem Mark17 0 1,262 Jan-27-2022, 01:02 AM
Last Post: Mark17
  Python VLookup? Lookup Table? Nu2Python 3 2,483 Oct-25-2021, 08:47 PM
Last Post: Nu2Python
  Unable to import Private Repo using setup.py Bob786 1 1,788 Sep-02-2021, 04:19 PM
Last Post: snippsat
  Can I replace IF statements with a key lookup ? jehoshua 3 2,573 Mar-05-2021, 10:24 PM
Last Post: jehoshua
  [split] Помощь по приватным ключам/Private key help sairam17519 0 1,627 Sep-07-2020, 12:55 PM
Last Post: sairam17519
  Download file from Private GitHub rep vinuvt 0 2,002 Jul-27-2020, 11:38 AM
Last Post: vinuvt
  Partial key lookup in dictionary GaryNR 1 3,504 Jul-16-2020, 06:55 PM
Last Post: Gribouillis
  Private package distribution abomination disadvantages research andreir 2 2,201 May-07-2020, 12:32 AM
Last Post: andreir

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020