Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

IP Address with variable

  • 06-02-2011 4:57pm
    #1
    Registered Users, Registered Users 2 Posts: 884 ✭✭✭


    Hi there,

    I need to get a piece of code (possibly Javascript) that will allow me to have a user input a number, say 1-200 and that variable would make up the last part of an IP Address that the user wants to browse to.

    192.168.0.[variable]

    Is there a script that will allow me to do that?


Comments

  • Closed Accounts Posts: 23,718 ✭✭✭✭JonathanAnon


    you could write a piece of code using HTML forms and PHP... but I dont know any situation where you would need to do such a thing? could you not provide the user with a list of IPs (or preferably host names) to choose from.. ??


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    you could write a piece of code using HTML forms and PHP... but I dont know any situation where you would need to do such a thing? could you not provide the user with a list of IPs (or preferably host names) to choose from.. ??

    JonathonAnon, we meet again. OP, we are going to need more to go on than "I need code, possibly in javascript, that does bla."

    Can you give us an idea what this will be going into, what the underlying system uses etc?

    As JA said, why would you need a user to select a number, which becomes an IP address. Sounds dodgy!


  • Registered Users, Registered Users 2 Posts: 811 ✭✭✭Rambo


    Cork Skate wrote: »
    Hi there,

    I need to get a piece of code (possibly Javascript) that will allow me to have a user input a number, say 1-200 and that variable would make up the last part of an IP Address that the user wants to browse to.

    192.168.0.[variable]

    Is there a script that will allow me to do that?


    Here a dos script just save it as p.bat
    on cmd line enter p.bat 1 the number you have chosen
    this will ping the machine

    REM -- Read in variable
    
    set num=%1
    ping 192.168.0.%num%
    
    pause
    


  • Registered Users, Registered Users 2 Posts: 184 ✭✭Razzuh


    I think this is what you seem to be looking for? I don't see why this could be of use to anyone though. Also, this is off the top of my head so I wouldn't actually recommend using it for anything, but it should give you an idea of what javascript for what you want would look like.
    <html><body>
    <form id="ip_form">
        <input type="text" id="ip" name="ip">
        <input type="button" value="get link" onclick="generateIP()">
    </form>
    <a id="link" href=""></a>
    </body></html>
    
    <script type="text/javascript">
    function generateIP()
    {
        var first3octets = "192.168.1.";
        var lastOctet = document.getElementById("ip").value;
        if(lastOctet >= 0 && lastOctet <= 255)
        {
            var ipAddress = "http://"+first3octets + lastOctet;
            var link = document.getElementById("link");
            link.href=ipAddress;
            link.innerHTML = ipAddress;
        }else{alert("Enter an integer in the range 0 - 255");}
    }
    </script>
    


Advertisement