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
  • Possible duplicate of [How do you append to a file?](https://stackoverflow.com/questions/4706499/how-do-you-append-to-a-file) – sco1 Mar 28 '18 at 03:17
  • Are you asking how to concatenate or how to use a function that returns a value or how to append to a file? – Nick is tired Mar 28 '18 at 04:37
  • i want to take the value 'ipaddress' and place it in a file like so f = open("test/test.txt", "w+") f.write("theipaddress") add address='tohere' list=st f.close() – lookoutitzjim Mar 28 '18 at 04:39
  • Then you need to read a tutorial on functions and how they work, because it appears you already know how to write to a file and how to get the IP to print, but don't know how to do anything with it – Nick is tired Mar 28 '18 at 04:41
  • okay thank you very much – lookoutitzjim Mar 28 '18 at 04:42

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,611
  • 12
  • 29