Get IP address visitor and execute Azure CLI

prod 0 Reputation points
2023-02-19T23:13:52.6533333+00:00

Hi,

please, I try to do the next:

  1. some public visitors with the browser come to mysite.com/temp_url_xxxxxxxxxx.html
  2. node.js get the IP address visitor and save in a variable ipVisitor = 55.168.22.22
  3. usign Azure CLI or other method, the script add the ipVisitor to Azure > Ubuntu 22.04 Virtual machine > Networking > Inbound port rules > to allow ipVisitor traffic usign HTTPS protocol. Ubuntu 22.04 Virtual machine is mysite2.com
  4. after add the new ip, node.js will redirect the user automatically to my mysite2.com

All is transparent to the visitors, just wait a few seconds.

Please can you recomend the best Azure product to do this small action?

(I am familiar with javacript)

I confuse about azure web app, function app, etc..

thanks in advance!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vasileios Dionysopoulos 641 Reputation points
    2023-02-21T22:58:46.04+00:00

    Hello,

    To achieve the functionality you described, you can use an Azure Function App with a custom JavaScript function. The function can use the Azure CLI to update the Inbound Port Rules of your Azure Virtual Machine based on the IP address of the visitor.

    Here's an overview of the steps you can take to implement this solution:

    1. Create an Azure Function App and a custom function with a JavaScript runtime.
    
    2. Configure the function to execute when the visitor accesses the /temp_url_xxxxxxxxxx.html URL.
    
    3. In the JavaScript function, use a library like Request.js to get the IP address of the visitor.
    
    4. Use the Azure CLI within the JavaScript function to add the IP address to the Inbound Port Rules of your Azure Virtual Machine.
    
    5. Once the IP address has been added, redirect the visitor to your mysite2.com domain.
    

    As for which Azure product to use, an Azure Function App would be a good choice for this scenario. Function Apps are designed to execute small pieces of code in response to specific events or requests. They are lightweight and can scale up or down as needed, which makes them well-suited for handling sporadic requests from visitors.

    In contrast, an Azure Web App is better suited for hosting full-fledged web applications or APIs, which is more than what you need for this scenario.

    I hope I give you a hint.

    0 comments No comments

  2. Vasileios Dionysopoulos 641 Reputation points
    2023-02-21T22:59:59.9966667+00:00

    To achieve the functionality you described, you can use an Azure Function App with a custom JavaScript function. The function can use the Azure CLI to update the Inbound Port Rules of your Azure Virtual Machine based on the IP address of the visitor.

    Here's an overview of the steps you can take to implement this solution:

    Create an Azure Function App and a custom function with a JavaScript runtime.
    
    Configure the function to execute when the visitor accesses the /temp_url_xxxxxxxxxx.html URL.
    
    In the JavaScript function, use a library like Request.js to get the IP address of the visitor.
    
    Use the Azure CLI within the JavaScript function to add the IP address to the Inbound Port Rules of your Azure Virtual Machine.
    
    Once the IP address has been added, redirect the visitor to your mysite2.com domain.
    

    As for which Azure product to use, an Azure Function App would be a good choice for this scenario. Function Apps are designed to execute small pieces of code in response to specific events or requests. They are lightweight and can scale up or down as needed, which makes them well-suited for handling sporadic requests from visitors.

    In contrast, an Azure Web App is better suited for hosting full-fledged web applications or APIs, which is more than what you need for this scenario.

    I hope I give you a hint to continue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.