Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

IP Address with variable

  • 06-02-2011 05: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