Get IP Address?

Discuss RoboTask here
Post Reply
kunkel321
Posts: 30
Joined: Sun Mar 15, 2020 5:23 pm

Get IP Address?

Post by kunkel321 »

Hi there,
RoboNewbie here, Is there a command to get my IP Address and assign it to a variable? I want to programatically determine where my laptop is online at.
-steve
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Get IP Address?

Post by Oleg »

In order to get your external IP you have to use some external service (for example myip.com). You can have internet access through multilevel routing. This depends on your network and your internet provider.
Look at my example. It get text from myip.com service and parse it. 1-st internet address in the text is you external IP.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1075658632
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1136"
Hide=INTEGER|0
ID=INTEGER|1284208314
LogOnAsUser=INTEGER|1
Name=STRING|"get my IP address"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER

[Actions\Action1]
ActionID=STRING|"A_CEF_PAGEINFO"
Enabled=INTEGER|-1
Name=STRING|"CEF Web Page Information"
Params=FOLDER

[Actions\Action1\Params]
address=STRING|"https://www.myip.com/"
autodownload=STRING|"0"
autologon=STRING|"0"
framecount=STRING|"0"
framevar=STRING|"-1"
gethtml=STRING|"0"
getlinks=STRING|"0"
gettext=STRING|"1"
hide=STRING|"0"
keep=STRING|"1"
overwrite=STRING|"0"
password=STRING|"qrbZKkj5gQM84QqaWN8oGOsNPV431tEpMNr9NS8X7XyRwc89D/aAAjsOy4Jy2xHiNPjOQSgA48LleWhRxk+K"
textvar=STRING|"txt"

[Actions\Action2]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|0
Name=STRING|"Create text file C:\systemp\downloads\info.txt"
Params=FOLDER

[Actions\Action2\Params]
encode=STRING|"0"
fileexists=STRING|"0"
filname=STRING|"C:\systemp\downloads\info.txt"
line0=STRING|"{txt}"
linecount=STRING|"1"
suppress=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_REGEXP_MATCH"
Enabled=INTEGER|-1
Name=STRING|"RegExp Match"
Params=FOLDER

[Actions\Action3\Params]
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{txt}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"(?m)^\d+\.\d+\.\d+\.\d+$"
savesubexpression=STRING|"1"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
subexpressionvar=STRING|"IP"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"found"

[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{found}"

[Actions\Action5]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""MyIP = {ip}"""
Params=FOLDER

[Actions\Action5\Params]
icon=STRING|"1"
msg0=STRING|"MyIP = {ip}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action7]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Something went wrong..."""
Params=FOLDER

[Actions\Action7\Params]
icon=STRING|"0"
msg0=STRING|"Something went wrong..."
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

Oleg Yershov
kunkel321
Posts: 30
Joined: Sun Mar 15, 2020 5:23 pm

Re: Get IP Address?

Post by kunkel321 »

Thanks for the Task scrip Oleg! It's pretty slick. Oddly I'm getting different values from different sources. If myip.com gets my 'external' IP Address, is there also an 'internal' IP Address? I have a clunky Autohotkey script that shows the value of a local variable %A_IPAddress1%. It yields a different number.
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Get IP Address?

Post by Oleg »

... is there also an 'internal' IP Address?
What address? every computer have local address 127.0.0.1 It is a localhost
Also if you use some router in your office (or home) computer has IP-address in your local network. Usually it is one of 192.168.1.xxx addresses
You can use VPN (for example open VPN) to connect to remote local network. System assigns some address too. The address depends on settings of VPN server.

But these addresses are not related to your internet connection.

To retrieve all assigned addresses you can use IPCONFIG system utility.
  • Press Win+R, type CMD and press Enter
  • In console window type ipconfig and press Enter
You can see all assigned IP addresses to your computer.
Oleg Yershov
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Get IP Address?

Post by Rukbunker »

Don't you mean {IPAddress({ComputerName})}??
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Get IP Address?

Post by Oleg »

Rukbunker wrote:Don't you mean {IPAddress({ComputerName})}??
This is the address in you local network.
It is not related to your internet connection at all.
This address can be assigned by DHCP server (usually built-in your router) or assigned manually in system settings of your computer.
Oleg Yershov
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Get IP Address?

Post by Rukbunker »

Ofcourse, I know that.

I was just replying to him:
kunkel321 wrote: is there also an 'internal' IP Address?
kunkel321
Posts: 30
Joined: Sun Mar 15, 2020 5:23 pm

Re: Get IP Address?

Post by kunkel321 »

Thanks for the replies. The one Rukbunker indicated is the other number that I was referring to. I just assumed that was the "IP Address."

EDIT: It's worth mentioning what I'm using this for... The public school district I work for uses different addresses for the different school buildings. I noticed a pattern at some point. While the last part of the address gets dynamically changed, the first part is always the same for a given school building. (See below). I made an Autohotkey script that assesses which building I'm at and sets the correct default printer for me to use.

;Home=10.0.
;Admin=10.14.
;KHS=10.15. or 10.150
;NKHS=10.6
;PMS=10.1.
;KMS=10.8.
;Breidablik=10.7
;Pearson=10.5.
;PoulsboElem=10.2.
;Gordon=10.1.
;Wolfle=10.4. or 10.40
;Vinland=10.16
;Suquamish=10.3.
Post Reply