0

Hello just a quick question people, I want to get a domain's IP address and post it into another file example

>> import socket
>> socket.gethostbyname('www.google.com')
'216.58.203.100'

I want to take '216.58.203.100' and place it into a separate file like this:

add address=216.58.203.100 list=st

Is this possible ? I'm only new to python and I'm not quite sure on what questions to ask.

-EDIT-

I understand appending a file put I'm just confused on how I take the the 'IP address' and place it in
( add address= RIGHT HERE list=st )

rrao
  • 297
  • 4
  • 11

1 Answers1

0

This should work

import socket
ip = socket.gethostbyname('www.google.com')
f = open('ipfile.txt', 'w+')
f.write("add address={} list=st\n".format(ip))
f.close()
Shiva Kishore
  • 1,451
  • 8
  • 26