How to get a node's IP address from the commandline?

Hi

I have a node that changes Ip add once in a while and I want to be able to figure out the ip address of the node in a scriptable way. I am wondering what is a good way to do it.

thanks

Use stfinddevice from the utils package. Available on build.syncthing.net, if its via global discovery. Otherwise you can just query syncthing via rest api, it will have the address it connected to.

Cool

Having a slight issue though, typed as you see below

./stfinddevice [-server=“udp4://xx.xx.xx.xx:22026”] MYNODE

just prints out the usage to me. I tried couple combinations without any luck, I even tried the Device ID.

Btw I am using my own global server

Note that square brackets mean “optional”. So either include the stuff inside them or don’t, but don’t include the brackets themselves.

This does not print out anything for me. it runs the command and nothing comes out of it.

./stfinddevice -server=“udp4://xx.xx.xx.xx:22026” XXXXXXX-KDZYSFC-XXXXXX-CGPVQW7-XXXXXX-HTUYM5R-XCGRMXS-XXXXXXX

It means it did not find the device.

does the stfinddevice from build.syncthing.net already use the new discovery protocol? Maybe that’s the problem and you need to compile it yourself from the 0.11 branch

1 Like

Indeed. Use this build for v0.11:

http://build.syncthing.net/job/syncthing-utils/103/

1 Like

Yup That works great.

Thanks for all the help

Is this communicatiung over secure layer at all?

Btw another anomoly. I fire 4 times and only it prints out the ip once. Sometimes it prints out right away sometimes I have to run the command multiple times. Is this an expected behaviour? I doubt that the node is dropping of the connection in such shorts amountof time.

I prefer this method because it is global and I do not have to have ST running locally.

thanks

No discovery protocol does not have any security. It’s UDP based, so packet loss can cause it not to return anything.

Thanks for the explanation.

Also, I think there is a 5 second timeout waiting for a response. If your discovery server runs on a calculator and is somewhere far away, it might not be enough.

it is weird because I am querying 3 nodes and in general the script is only able to print 1 at a time but sometimes it gets 2 ips.

You can only query one node per invocation. You might get multiple ips if there was multiple reports from different IPs in the last 30minutes, or the situation has changed, for example you got a new UPnP mapping.

As someone mentioned that a solution can be to query the REST api, this is my small python3 script to get device IPs and their human readable names:

st-get-ip

Thanks for the script. I prefer the global method because I do not have to have ST running but I will use your script on another local device.