Batch/cmd: saving ping logs to a file and getting the summary paragraph afterwards - windows

I'm trying to use ping to monitor my internet connection overnight and watch for connection dropouts, packet loss, latency spikes, and so on. I have a batch file that pings google each second and records the results to a file:
#echo off
ping -t www.google.com|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!time! !data!)&ping -n 2 localhost>nul" > ping_logs_google.txt
And I get output like this:
16:36:50.47 Pinging www.google.com [209.85.202.106] with 32 bytes of data:
16:36:51.50 Reply from 209.85.202.106: bytes=32 time=31ms TTL=47
16:36:52.52 Reply from 209.85.202.106: bytes=32 time=31ms TTL=47
16:36:53.54 Reply from 209.85.202.106: bytes=32 time=30ms TTL=47
16:36:54.58 Reply from 209.85.202.106: bytes=32 time=29ms TTL=47
16:36:55.61 Reply from 209.85.202.106: bytes=32 time=32ms TTL=47
16:36:56.64 Reply from 209.85.202.106: bytes=32 time=32ms TTL=47
.. and so on. However, when I press Ctrl-C or whatever to stop the task, I want to get the summary paragraph at the end. The one that looks like this:
Ping statistics for 209.85.202.106:
Packets: Sent = 9, Received = 9, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 29ms, Maximum = 34ms, Average = 30ms
Control-C
^C
Now, this does work when I press Ctrl-C after running just "ping -t www.google.com" in the command window itself -- it just doesn't work when I run it from the batch file. How do I make it so that I get the summary paragraph at the end when I'm finished with the batch file?

Instead of running continuously with -t, replace with "-n 100", where "100" is the number of times it will ping (or 1000 if you like). This will give you the summary at the end of your output file the same way it does in the command window. However, you'll want to remove any pauses, etc. and just it rip.

Related

set proxy through windows command line without login parameters

I have some proxy applications like Ultra-surf or Tor-browser. I can set their proxy in browsers or on other applications. For example for Tor, I can set socks: to "127.0.0.1:9150" in any application.
but I want to using this proxy for CMD.
I saw these answers
netsh winhttp set proxy proxy-server="socks=localhost:9090" bypass-list="localhost"
Or
set HTTP_PROXY=http://proxy_userid:proxy_password#proxy_ip:proxy_port
I opend a CMD as an Administrato, and then I tried these commands. After each one, I tested 3 sites: "google.com" and "facebook.com" and "youtu.be". But noting was changed. "google.com" always works and "facebook.com and youtu.be" do not work. Also, It does not make difference if my proxy apllication be open or not.
Anyone knows how can I set this kind of proxy for CMD?
netsh winhttp set proxy 127.0.0.1:1080
netsh winhttp set proxy proxy-server="socks=127.0.0.1:9150" bypass-list="127.0.0.1"
netsh winhttp set proxy proxy-server="socks=localhost:9150" bypass-list="localhost"
netsh winhttp set proxy proxy-server="http=127.0.0.1:1080" bypass-list="127.0.0.1"
netsh winhttp set proxy proxy-server="https=127.0.0.1:1080" bypass-list="127.0.0.1"
set HTTP_PROXY=127.0.0.1:1080
set HTTPs_PROXY=127.0.0.1:1080
set HTTP_PROXY=#127.0.0.1:1080
set HTTPs_PROXY=#127.0.0.1:1080
set HTTP_PROXY=:#127.0.0.1:1080
set HTTPs_PROXY=:#127.0.0.1:1080
The ping response always is:
For not sensored site:
C:\>ping google.com
Pinging google.com [172.217.18.142] with 32 bytes of data:
Reply from 172.217.18.142: bytes=32 time=198ms TTL=51
Reply from 172.217.18.142: bytes=32 time=94ms TTL=51
Reply from 172.217.18.142: bytes=32 time=95ms TTL=51
Reply from 172.217.18.142: bytes=32 time=102ms TTL=51
Ping statistics for 172.217.18.142:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 94ms, Maximum = 198ms, Average = 122ms
For sensored sites:
C:\WINDOWS\system32>ping youtu.be
C:\WINDOWS\system32>ping facebook.com
Pinging facebook.com [10.10.34.35] with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 10.10.34.35:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

Custom domain does not work for homestead

I'm brand new to using homestead for developing laravel sites locally. I followed two different tutorials for setup and have reinstalled about 5 times, but the custom domain name does not work for me. I'm working on a windows 10 machine and am using Virtualbox. I'm able to see the test site when I browse to 192.168.10.10 in my browser. I can ping 192.168.10.10 and get all of the packets send and receive fine. I can also ping obsessories.dev it sends and receives all of the packets successfully. I also tried changing my hosts file to use 127.0.0.1 based on another answer I saw on SO, but that didn't work for me. I use the command
vagrant reload --provision
each time I make any change to Homestead.yaml and my hosts file. I have noticed that firefox and chrome both redirect to https://obsessories.dev, but I'm not sure if that's a problem or not. I appreciate any help or insight on this in advance!
Here is my Homestead.yaml file:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: C:\Users\******\Projects\web\ssh\publickey.pub
keys:
- C:\Users\******\Projects\web\ssh\privatekey.ppk
folders:
- map: C:\Users\******\Projects\web\sites
to: /home/vagrant/code
sites:
- map: obsessories.dev
to: /home/vagrant/code/obsessories/public
databases:
- homestead
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# zray:
# If you've already freely registered Z-Ray, you can place the token here.
# - email: foo#bar.com
# token: foo
# Don't forget to ensure that you have 'zray: "true"' for your site.
output for pinging 192.168.10.10
ping 192.168.10.10
Pinging 192.168.10.10 with 32 bytes of data: Reply from 192.168.10.10:
bytes=32 time<1ms TTL=64 Reply from 192.168.10.10: bytes=32 time<1ms
TTL=64 Reply from 192.168.10.10: bytes=32 time<1ms TTL=64 Reply from
192.168.10.10: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.10.10:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
output for pinging obsessories.dev
ping obsessories.dev
Pinging obsessories.dev [192.168.10.10] with 32 bytes of data: Reply
from 192.168.10.10: bytes=32 time<1ms TTL=64 Reply from 192.168.10.10:
bytes=32 time<1ms TTL=64 Reply from 192.168.10.10: bytes=32 time<1ms
TTL=64 Reply from 192.168.10.10: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.10.10:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Joe's suggestion worked for me. I changed the domain to .local instead and reloaded vagrant and works just fine now.

Ping on shell scripts: Some packet loss, but error code $? equals to zero. How can I detect?

Sometimes my DSL router fails in this strange manner:
luis#balanceador:~$ sudo ping 8.8.8.8 -I eth9
[sudo] password for luis:
PING 8.8.8.8 (8.8.8.8) from 192.168.3.100 eth9: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=47 time=69.3 ms
ping: sendmsg: Operation not permitted
64 bytes from 8.8.8.8: icmp_seq=3 ttl=47 time=68.0 ms
ping: sendmsg: Operation not permitted
64 bytes from 8.8.8.8: icmp_seq=5 ttl=47 time=68.9 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=47 time=67.2 ms
ping: sendmsg: Operation not permitted
64 bytes from 8.8.8.8: icmp_seq=8 ttl=47 time=67.2 ms
^C
--- 8.8.8.8 ping statistics ---
8 packets transmitted, 5 received, 37% packet loss, time 7012ms
rtt min/avg/max/mdev = 67.254/68.183/69.391/0.906 ms
luis#balanceador:~$ echo $?
0
As can be seen, error code $? is 0. So I can not simply detect if the command failed, as the output yields no error for any script.
What is the proper way to detect that there were some packet loss?
Do I need to parse the output with grep or there is some simpler method?
According to the man page, by default (on Linux), if ping does not receive any reply packets at all, it will exit with code 1. But if a packet count (-c) and deadline timeout (-w, seconds) are both specified, and fewer packets before timeout are received, it will also exit with code 1. On other errors it exits with code 2.
ping 8.8.8.8 -I eth9 -c 3 -w 3
So, the error code will be set if 3 packets are not received within 3 seconds.
As #mklement0 noted, ping on BSD behaves in a bit different way:
The ping utility exits with one of the following values:
0 - at least one response was heard from the specified host.
2 - the transmission was successful but no responses were received.
So, in this case one should try workaround it with sending one by one in a loop
ip=8.8.8.8
count=3
for i in $(seq ${count}); do
ping ${ip} -I eth9 -c 1
if [ $? -eq 2 ]; then
## break and retransmit exit code
exit 2
fi
done
Of course, if you need full statistics, just count codes "2" and "0" to some variables and print result / set error code after for loop if you need.

Windows console command for finding server site is deployed to

I have a url to a site and I vaguely remember there being a Windows console command that you can use to find the IP address of the server the site is deployed to. Can someone remind me? Also, can you tell me how to use it?
if you ping the server using the Windows command prompt, it will gives you the server IP.
ex.: ping www.google.com
C:\Users\Deleu>ping www.google.com
Pinging www.l.google.com [177.99.189.241] with 32 bytes of data:
Reply from 177.99.189.241: bytes=32 time=34ms TTL=58
Reply from 177.99.189.241: bytes=32 time=36ms TTL=58
Reply from 177.99.189.241: bytes=32 time=38ms TTL=58
Reply from 177.99.189.241: bytes=32 time=38ms TTL=58
Ping statistics for 177.99.189.241:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 34ms, Maximum = 38ms, Average = 36ms
C:\Users\Deleu>
You need nslookup.
Nslookup.exe is a command-line administrative tool for testing and
troubleshooting DNS servers. This tool is installed along with the
TCP/IP protocol through Control Panel. This article includes several
tips for using Nslookup.exe.
c:\Temp>nslookup google.com
Server: BoB.Orcon
Address: 10.1.1.1 <------ Name server
Non-authoritative answer:
Name: google.com
Addresses: 2404:6800:4006:804::1004 <----- Answer in ipv6
74.125.237.128 <----- Answer in ipv4
74.125.237.137 <----- Other answers....
74.125.237.134 .
74.125.237.132 .
74.125.237.135 .
74.125.237.133 etc
74.125.237.136 .
74.125.237.142 .
74.125.237.130 .
74.125.237.131 .
74.125.237.129

Is it possible to create an async build step?

I would like to start an application from a pre-build step. However, I do not want Visual Studio to wait for the application to close.
Basically, I have a simulation engine that I need to start prior to a debugging session.
Is this possible? I tried commands like "start app.exe" and "cmd start app.exe"...
Is "start /b" what you're looking for? It starts the command and returns immediately.
C:\>start /b ping stackoverflow.com
C:\>
Pinging stackoverflow.com [69.59.196.211] with 32 bytes of data:
Reply from 69.59.196.211: bytes=32 time=153ms TTL=44
C:\>Reply from 69.59.196.211: bytes=32 time=153ms TTL=44
C:\>Reply from 69.59.196.211: bytes=32 time=153ms TTL=44
C:\>
C:\>Reply from 69.59.196.211: bytes=32 time=154ms TTL=44
Ping statistics for 69.59.196.211:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 153ms, Maximum = 154ms, Average = 153ms
C:\>
This is how I ended up doing this.
It was kind of a "duh" moment, but I created a simple console application that starts a process and returns.
Thanks to Eugene for the suggestion.

Resources