Using geo-like functionality on another variable

I’d like to be able to do something like:

grab variable from arguments

if ($args ~ “ip=([0-9.]+)&”) {
set $iparg $1;
}

set country based on variable

map $iparg $country {
default international;
192.168.0.0/16 us;
}

where I could use geo-like functionality on another variable besides
$remote_addr.

Or I’d like to be able to pass another variable to geo, like:

grab variable from arguments

if ($args ~ “ip=([0-9.]+)&”) {
set $iparg $1;
}

set country based on variable

geo $iparg $country {
default international;
192.168.0.0/16 us;
}

Is there any way to do this? I tried setting $remote_addr to another
value, and got an error. I could script the generation of the mapping
of each ip to a different line in a file for use inside a map directive,
but I wanted to see if there’s an easier, more direct way.

Thanks!