Connect to server on any WI-FI network without thinking about IP addreses

It's nice that all you need on the client device is a supported web browser. Actually, this is the main reason why I was (an still am) excited about O-S-C: the ability to connect using almost any device.

Over the time though, I've noticed that, on different WI-FI networks, the IP address of the laptop (or any computer, in general) is changed. Most home routers I've connected to will assign the laptop an IP of this form: 192.168.0.x (x is the varied number), while other ones (routers at my University, for example) will assign an IP of this form: 192.168.y.x.

While I know of the possibility that allows you to assign multiple static IPs (both on winOS and macOS), I wonder if it's possible to connect to the server without thinking about the IP address at all. In other words, I wonder if I could just have a bookmark that says: "127.0.0.1/osc" (or something similar) and connect to it successfully, no matter what IP gets assigned to the server computer.
I know that this would require me to install/have additional software on my client devices (windows tablet & android phone), but is there any chance that a configuration like this could be created?

Thank you!

hi

what about using your os host file ?

myoscserver 192.168.0.100
myoscserver 192.168.1.100

then in a browser http://myoscserver
i really don't know if it can work
best

1 Like

According to this, the port number should also be included when you type the address in the browser.
So, in order work, the address you type should look like this:
http://myoscserver:8080/

I believe I can write an AHK script to:
1 — Ping the computer running the server;
2 — Extract the IP address and store it in a variable;
3 — Replace the "192.168.43.2 myoscserver" line in the "hosts" file with this one:
"%new_IP% myoscserver"

@Greenman, your idea turns out to be part of the solution. Thank you!

hi @theodor_the_1st

I can be interested by your AHK script, i guess you're talking about https://www.autohotkey.com/

I've created a thread on the autohotkey forum.
Here's the link: Replace an IP in the "hosts" file with the IP from a ping result - AutoHotkey Community

I'll share the script once I get it working.

O-S-C announces itself on the network using bonjour/zeroconf, what would be ideal is a bonjour/zeroconf app on the client side that detects o-s-c and browses to it. The thing is I don't develop native apps for mobile operating system, but it's something worth looking at.

2 Likes

Automatically change the IP address of the osc_server domain name in the hosts file AHK script.
Thank you, @Greenman (for the hosts idea) and @GeneralMidi (for the AHK OSC integration DLL link - posted here)

Now, if I connect my O-S-C server device and my client device to another router, all I have to do is run the script, and my bookmark (http://osc_server:8080) will be automatically linked to the correct IP.
Hurray! :partying_face:


Autohotkey code
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

!z:: Reload

!a::
; Variables
serverComputerName := "aaa" ;
domainName := "osc_server"

; 1) new_ip variale
; (store the IP of the computer named "aaa" into the "%new_ip%" variable)
; Credit goes to mikeyww (https://www.autohotkey.com/boards/memberlist.php?mode=viewprofile&u=59977)
Clipboard =
RunWait, %ComSpec% /c ping -n 1 %serverComputerName% | clip,, Hide
ClipWait, 0
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 Return
} Else RegExMatch(Clipboard, "Reply from \K[\d.]+", new_ip)

; 2) LineNum variable
; (store to a variable the line number in which "osc_server" is contained; this helps in finding which line should be replaced in the next step)
strToFind := %domainName%
Loop, Read, c:\Windows\System32\drivers\etc\hosts
{
         IfInString, A_LoopReadLine, %strToFind%
            {
               LineNum := A_Index
             } 
}

; 3) Replace the line containing "osc_server"
newLineContent = %new_ip% %domainName%
Loop, Read, c:\Windows\System32\drivers\etc\hosts
	{
		If A_Index = %LineNum%
			FileAppend, %newLineContent%`n, %A_Temp%\Temp.txt
		Else
			FileAppend, %A_LoopReadLine%`n, %A_Temp%\Temp.txt
	}
FileMove, %A_Temp%\Temp.txt, c:\Windows\System32\drivers\etc\hosts, 1

cool and i will try asap. thanks for your sharing !

edit : next step, what about mobile devices ?

You're welcome!


On android I can't use the "ping aaa" command...

Screenshot

It's a bit funny, because these commands work:
ping www.google.com
ping 192.168.43.2

We need to find a way to query the IP address of the computer running the server using the terminal.

Hey! I would love to try this for myself but I'm having trouble getting this running. I saved your code in a new AutoHotKey script, downloaded OSC2AHK.dll and put in same folder as script and can't get it to work. Any help would be much appreciated as I would love to not worry about inputing a new IP address everytime I open up OSC on my ipad

Hi, @mrkapow !
The script must be run from the client device (in your case, from an iPAD). Now, I don't know much about iPads, but I'm pretty sure you can't run AHK on such a device. Maybe find another scripting solution?

I think you can start here:

Then find a scripting app or find out maybe you can do this in bash (hope iPad has bash...)

Edit: Does client device mean, the device connected to the host? Cause I am running from my laptop and connecting with ipad for midi controller

Thank you so much! I'll give it a go and find out! Thank you!

My pleasure!

Client device = the device that you usually connect to the server using an internet browser.
Server device = the device that runs the O-S-C server.

If you find a solution, please post it.

In next version, the server will provide a qrcode to help connecting mobile devices

3 Likes