0

clueless about next step to take in writing my code

today im writing the next part of my code which does a ping on a broad range of ip addresses, ive got the counter complete but now i need to create the function which does a ping on each address, and im completely clueless on even which loop to use, and would the "window.location" method come into play here because im thinking i should be sending the code to carry itself out on my shell terminal, is that wrong?, im gonna start some trial and error sequences right now, open to any suggestions though

16th Jul 2017, 5:53 PM
Escobar
Escobar - avatar
16 Respuestas
+ 1
Array.push(value) will add a value to an array after the highest existing index.
23rd Jul 2017, 4:16 AM
James
James - avatar
+ 1
dude thats brilliant, i was completely off, how is it that i learn all these methods and loops but i never think to put it together with all ive learned like i either forget a particular loop or function, i mean seriously when i get stuck somewhere and have to ask for help the answers so simple it just makes me look at myself like what an idiot, look this is where i ended up https://code.sololearn.com/W9Hwh0tkXRDo/?ref=app
17th Jul 2017, 9:35 PM
Escobar
Escobar - avatar
+ 1
Yes, in my example address.length is 2. So the loop will run through keys 0 and 1 but then stop, because k < address.length, that is 2 < 2, is false. The .length array method is predefined to give the number of values in an array; but, address is not predefined.
19th Jul 2017, 5:52 AM
James
James - avatar
+ 1
understood, but thanks a bunch for the way you just sharpened me on my javascript, i learned alot, however still have a long way to go, is there a way we can stay in better close contact as i learn? i dont mean to be a bother though' its just a bit difficult learning this without a guide or a professor..
28th Jul 2017, 7:43 PM
Escobar
Escobar - avatar
0
If you put the addresses into an array, you can loop through the keys and stop at the array length. var address = ["161.27.1.1", "162.12.1.90"]; for (var k = 0; k < address.length; k++){ //Your code here // Refer to the current address using address[k] }
16th Jul 2017, 11:33 PM
James
James - avatar
0
hey maybe im wrong, cuz ive yet to test this but wouldnt the array length be "2" right here???
19th Jul 2017, 3:34 AM
Escobar
Escobar - avatar
0
or is address an already predefined object?
19th Jul 2017, 3:35 AM
Escobar
Escobar - avatar
0
but i didnt find complete fault in your suggestion, i think it gave me a clue, like var a="167.192" function address(){ for(x=0;x<255;x++){ for(y=0;y<255;j++){ document.write(a+"."+x+"."+y } } return= addresses } var addresses [ /* do i really have to copy and paste all those adresses in this array or can i just put either the previous functions name or its return? */ ] var b= 0 while(b<array.length){ window.location= address().return } or is this just outrageously wrong??
21st Jul 2017, 2:26 AM
Escobar
Escobar - avatar
0
That's a good idea, but your code isn't entirely correct. This will fill up the array. var addresses = []; var a = "167.192."; for (var x = 0; x <= 255; x++){ for (var y = 0; y <= 255; y++){ addresses.push(a + x + "." + y); } } I didn't understand what you were trying to do in the second part with var b.
21st Jul 2017, 5:24 AM
James
James - avatar
0
the push part, what does that do? does that push my functions outcome to my arrays value? where is that discussed in javascript>core objects>arrays? or is that something that isnt duscussed and is in the list of javascrips ore defined functions?
23rd Jul 2017, 3:50 AM
Escobar
Escobar - avatar
0
at that second part im gonna use the values of my array and test each one with a ping command in a terminal window, i chose to go with an if statement but im not sure if i would put "ping into a string as a variable, it should work, i think if(addresses===(/*ping response*/){ document.write(/*address with ping response*/); continue; } i googled the list of javascripts pre defined methods, its a slew of em, lol, im studying them now, instead of document.write() im going to find a method that automatically saves the output to a file... but as said, im testing the outputs in my terminal so i think i may do a string with the word ping that concatenates with the ip outputs and then test itself, but i ha e to learn how to make a function link with an application, which i think ill discover in javascripts pre defined methods...
24th Jul 2017, 4:00 AM
Escobar
Escobar - avatar
0
Put a loop in a loop. One going through the addresses array keys, the other going through an array of valid pings. Then you can use both keys in the if statement. Need a demo?
24th Jul 2017, 5:44 AM
James
James - avatar
0
no, not just yet, let me give a swing at it first and if i get stuck, ill ckeck back, ill learn better that way...
24th Jul 2017, 6:02 PM
Escobar
Escobar - avatar
0
ok var num=0; array newvalidAddresses=[]; array validAddresses=["167.192.96.83","167.192.96.13","167.192.96.14"]; function testip(){ while(num<addresses.length){ num++; } num.src= addresses[num] validAddresses.keys===/*(ping responsive) not sure what to place here to make javascript understand these addresses are ping responsive, and make the if statement understand that if it encounters an address that gives it a response identical (===) to those ping responses then the statement is true, i mean like, what is pings output???*/ if(addresses.keys===validaddresses.keys){ newvalidaddresses.push(/*true*/) } document.write(newvalidaddresses.keys) } i fear my if statement will only display thecaddresses of the validaddresses array when it encounters those same addresses....
24th Jul 2017, 8:21 PM
Escobar
Escobar - avatar
0
Ok, wait a sec. You now need to know how to actually test a ping, like send a package and wait for a reponse? I'm not sure you can use JavaScript for that... JavaScript is just a language for opening and running but not saving and sending (without add-ons). Perhaps make a new question, "How to get a ping response?" or try Google. Node.js is an add-on IDE that I have heard of for JavaScript that might work, but I have never tried it.
25th Jul 2017, 12:59 PM
James
James - avatar
0
I'm also learning myself and am definitely not a master, but I'll follow your SoloLearn account and try my best to answer any questions.
29th Jul 2017, 12:20 AM
James
James - avatar