Streamlit Get the Client IP address

from streamlit import runtime
from streamlit.runtime.scriptrunner import get_script_run_ctx

def get_remote_ip() -> str:
    """Get remote ip."""

        ctx = get_script_run_ctx()
        if ctx is None:
            return None

        session_info = runtime.get_instance().get_client(ctx.session_id)
        if session_info is None:
            return None
    except Exception as e:
        return None

    return session_info.request.remote_ip

import streamlit as st

st.markdown(f"The remote ip is {get_remote_ip()}")

Hi @Anthoniraj_Amalanath

As mentioned in one of the reply (Log connected IPs and client information to console and/or file · Issue #602 · streamlit/streamlit · GitHub) in the provided link to the GitHub issue, logging IP has privacy implications.

Instead, perhaps this article on user analytics of Streamlit apps might be of interest:

There is no privacy implications accessing ip address of the client. Every web applications provide this feature. Assume that the dashboard is hosted in onpremise server and need to store all client access logs for security purposes in streamlit dashboard. We need this feature in streamlit. It is upto developer to use or not.

Feel free to share your thoughts on this feature request in the GitHub Issue that Chanin linked (here) so that our product and engineering teams can check out your feedback.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.