You can get the origin ip address with frappe.local.request_ip on server side.
Guessing the country will need an (really) updated database, this is the reason to use external API service.
I have tried frappe.local.request_ip as you suggested but got an error, my code is
ip = frappe.local.request_ip
# ip_split = list(map(int, ip_address.split('.')))
# country = frappe.db.sql('select country_code where "'+ip+'" between start_ip and end_ip;')
frappe.responce['message'] = str(ip)
and got error
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 95, in application
response = frappe.api.handle()
File "apps/frappe/frappe/api.py", line 55, in handle
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 48, in handle
data = execute_cmd(cmd)
File "apps/frappe/frappe/handler.py", line 72, in execute_cmd
return run_server_script(server_script)
File "apps/frappe/frappe/handler.py", line 90, in run_server_script
response = frappe.get_doc("Server Script", server_script).execute_method()
File "apps/frappe/frappe/core/doctype/server_script/server_script.py", line 98, in execute_method
_globals, _locals = safe_exec(self.script)
File "apps/frappe/frappe/utils/safe_exec.py", line 85, in safe_exec
exec(
File "<serverscript>", line 7, in <module>
File "apps/frappe/frappe/utils/safe_exec.py", line 483, in _write
raise SyntaxError(f"Not allowed to write to object {obj} of type {type(obj)}")
SyntaxError: Not allowed to write to object <function NamespaceDict.__getattr__.<locals>.default_function at 0x771bddd3a950> of type <class 'function'>
does this work with API server script. it returns none
{ "message": "None" }
Looking through implementation, even if there is no X-Forwarded-For,REMOTE_ADDR headers the result should be 127.0.0.1 unless the function not executed