0

This is my code

import socket
ip=56.90.89.78
ip2=str(IP)
M=socket.gethostbyaddr(ip2)
print (m)
2
  • 2
    Please provide a minimal reproducible example. ip=56.90.89.78 is a syntax error in Python. Or are you asking about that? In Python, string literals are written using single or double quotes, so this could just be ip = "56.90.89.78" or ip = '56.90.89.78' Commented May 24, 2020 at 10:03
  • what does the capital IP in ip2=str(IP) in reference to? Also ip=56.90.89.78 results in a syntax error, could you please provide more information Commented May 24, 2020 at 10:04

2 Answers 2

1

You have to save your ip adress as a string and not a float or integer because it has multiple decimals. Also you need to be consistent with your upper and lower cases. Your code should be:

import socket 
ip = "56.90.89.78"
M = socket.gethostbyaddr(ip)
print(M)
Sign up to request clarification or add additional context in comments.

Comments

0

If you just want to "convert" a literal IP address into a string, then like juanpa mentioned, it's just a matter of quoting in single or double quotes:

ip = "56.90.89.78"

If on the other hand, you want to resolve the IP address to a name, then you could indeed use the socket.gethostbyaddr function:

import socket
ip = "56.90.89.78"
name = socket.gethostbyaddr(ip)
print(name)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.