fping on windows

I started working on a ping plotter a while ago and back then I still was on linux and was currently getting into C. Now that I’m not on linux anymore I kinda dropped the project for a while. After that pause I’ve finally gone back I decided to ditch C and write it in Python since I’m developing it on windows but want it to work on linux aswell. The ping plotter is supposed to ping an ip over a timespan and then make a graph out of the latency values. For that I’ll use the ping command since that’s the easiest way to get latency values without adiministrative rights. The issue is that the windows ping.exe and the linux ping command return different outputs so formatting them means I have to differenciate between windows and linux.

After some searching I came across fping which is a custom ping program for linux. It’s designed to be used in scripts which digest it’s output. So now the only issue is to compile that for windows. I used cygwin for it since nobody seems to have done it before me. Sadly the build script returns errors when compiling. So here’s how I fixed that:

First get the sourcode from the releases. Now we’ll need to convince cygwin that we have the right headers. Download this header file (made by John Paul Morrison) as icmp.h. Copy it into these folders and replace it with the icmp.h that is in those folders (That one is empty, you can open it if you want):

\usr\include\icmp.h
\usr\include\cygwin\icmp.h

The path to cygwin will usually be C:\cygwin64\ or C:\cygwin\. Now you can run

$ ./configure
$ make

Now you’ll have a fping.exe in the ./src/ folder. Run a command prompt as admin and then run something like

C:\fping\src>fping.exe -s google.com

That should give someting like this

google.com is alive

       1 targets
       1 alive
       0 unreachable
       0 unknown addresses

       0 timeouts (waiting for response)
       1 ICMP Echos sent
       1 ICMP Echo Replies received
       0 other ICMP received

 36.6 ms (min round trip time)
 36.6 ms (avg round trip time)
 36.6 ms (max round trip time)
        0.038 sec (elapsed real time)

Pretty cool, huh? But if you read carefully it needs adminstrative rights on windows and root rights on linux so all of that was kinda wasted… I’ll just use the output of the native ping commands instead but if anyone needs fping on windows here you go. For those whore are to lazy to compile it themselves you can download my compiled binary for windows here (By the way there seems to be an infected version of fping on the web so if you need some confidence, that this one isn’t a virus heres a virustotal scan or scan it yourself). It’s completely unmodified and all credits go to the original authors.

I’ll now go back to getting back into python and formatting ping command outputs. Wohoo.

Clearscreen

I mentioned a while ago that I got a second monitor, which a long needed upgrade for me. I’ve been using only one screen for quite a while and for a lot of things it can get very frustrating to only have one screen. For example when playing a game in fullscreen your entire screen space is used up by one program, or when I needed to run two instances of a program for debugging, or when working on any project which requires to switch between programs like the webbrowser and something like Powerpoint.

Now that I have that second screen it’s obviously a lot more comfortable doing these things, but from time to time I still turn the other screen off because I notice that I don’t need it. The problem that comes up with that is that Windows remembers where you closed a program, so when opening for example the taskmanager and the last time I used it it was on the second monitor, I won’t see it since it’s turned off. So for now I’ve always either turned it back on again or just blindly guessed where the program is and dragged my mouse around in the dark.

Since that’s not an efficient solution I put together a small program that’ll move all windows (Almost all windows) that are open on one screen to another.

The program gets all it’s settings over arguments and is generally really small and probably unfinished but it does the trick for me. You pass it the dimensions of your main screen (Left, Right, Top, Bottom coordinates), which you can find out by running the progam with the –setup flag and finally pass it the coordinates of a point to which it should move all programs on the main screen.

It works pretty ok, it just doesn’t seem to want to move the file explorer since it’s probably the same process as the taskbar. At some point it also moved my taskbar, which made up for some interesting results like two taskbars stacked onto eachother. So I ended up blacklisting the explorer process.

And as always here‘s the sourcecode and the binary. I suggest launching the program from a shortcut with arguments.

MPD Query

So I mentioned in another post that I use mpd and ncmpcpp to listen to music. The positive thing about this is that I can just close ncmpcpp when I don’t need it anymore and the music will continue playing, since mpd is responsible for the sound which is running completely in the background. Now sadly I have no indicator about what song is playing right now.

So I looked if anybody made a patch for dwm to display the current song, but everything I found didn’t really work for me. And I didn’t want a bash script to be running in the background. So I found a few people suggesting to make a simple C program to query the current song.

Now this is easier said than done, since I have no idea how to use mpd and C. The first thing I did was download the source code of mpd and copied the include directory into my project folder. So now I can write a program utilizing code from mpd. Now for the tricky part: Getting my program to connect to mpd and get the song name and some other information. I had some example code which showed how to connect and get the play time of the current song, so that helped a little bit, but getting the song name doesn’t work the same way.

For experienced people this task probably would be a thing of ten minutes but I not only had to deal with how mpd worked I also had to figure out how C works. And most time that was me writing like three lines of code, compiling it and finding out it compiled fine but crashed when running. So here’s what I have done so far:

Created a Makefile where the include directory (which containes the headers of mpd) is:

Makefile

VERSION = 3.02
CC      = /usr/bin/gcc

mpdq: mpdq.c
    $(CC) -o mpdq -lmpdclient mpdq.c

So this way compiling is just the command ‘make’. Next up is writing the actual code which started by me finding out how the main method looks in C and then moving onto actually fiddling with mpd. To work with mpd I needed these two headers:

#include <mpd/client.h>
#include <mpd/stats.h>

When those are included and the compiler doesn’t complain about not finding them you should be able to access the necessary methods to connect and query information from mpd:

struct mpd_connection  *connection = mpd_connection_new(NULL, 0, 0);

This will open a connection to the local mpd and return the pointer to the connection if it succeeded. The three arguments are only needed if the connection is to another computer. After that we want to get the current song and from that we can read most Song tags:

// Get current song as a struct
struct song = mpd_run_current_song(connection);
// Read name and artist
char *song_name   = (char *) mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
char *artist_name = (char *) mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);

And that is technically everything important to read information from mpd. The only other things I did were putting this in a loop, adding a command to make it appear in the dwm bar, differentiating between paused/playing and  cleaning up when closing. That’s all I have done up until now. I’ll see if I can get some controls like pause/play into the dwm bar but for now this’ll suffice.

DMEDYKJ

Here‘s the source code and here‘s a binary build. Just give it the run flag with chmod a+x and when running it should display the current song in the top left corner (Provided you use dwm and a song is playing in mpd :P).

jBeamChat

So I’ve been using beam.pro now and then and I also did a few test streams. The problem I had is that since I don’t have a second monitor looking at the chat is rather hard when working on something that takes up your entire screen.

I tried to use an old laptop that I have to open up the embeded chat, so it could act as a second monitor. Sadly the old Pentium III and only 256 MB of ram couldn’t handle the beam.pro site even with arch linux and dwm. Which is probably nothing surprising, since that laptop is probably over 10 years old.

But then I discovered, that beam has it’s own API for java and a very handy tutorial which thoroughly describes how to use the API, so that even I could understand it, I started to write a chat client for Beam.

So only after about two hours I got a basic chat client which logs you in, echos all messages and lets you send your own.

After a few more hours I got username formatting with colors, if supported and your usual IRC formatting (eg. @, &, ~ etc.) if colors aren’t supported by the terimal. I also added a ping sound if someone mentions your name, and I’m working on some simple commands like listing current users.

This is an older version, but as you can see it’s running and even that old laptop runs with over 100 MB of RAM free and only about 10% CPU usage out of 1.1 GHz.

Obviously Java isn’t the goto language if you’re looking for high performance, so maybe I’ll see if I can rewrite this with the Python version of the API.

To keep the tradition going here’s the sourcecode and the binaries.

Conway’s game of life

Today I randomly decided to try and replicate the game of life using SDL2 and C++.

Surprisingly I got pretty far in one go and didn’t scrap the idea after 10 minutes but in the end I realized that my version doesn’t behave like the actual game of life, since it doesn’t exactly follow the rules.

Anyway, the game basically consists of a square field which is devided up into cells. These cells can either be alive or dead.

The state of cells can change by the following rules:

  • If a dead cell is surrounded by exactly three living cells it’ll become alive in the next generation.
  • If a living cell has only one living neighbor it’ll die in the next generation
  • If a living cell has two or three living neighbors it’ll stay alive
  • If a living cell is surrounded by four or more living cells it’ll die

Surrounding means all eight cells around it, directly connected or diagonally. Seems simple enough right? Well I still managed to fudge it up, since mine doesn’t quite stick to these rules, but it still produces some cool results.

Selfhtml

So, yeah don’t expect too much it’s only about 300 lines of bad structured c++. And as always here’s the sourcecode and binaries. (Also includes a linux build)

 

CS:GO Text generator

Another .NET App

This time it’s a console application though. And it’s purpose is rather questionable. What it basically does is generate a random sentence made out of random cyrillic letters, inserting words like “vodka” or “cyka” at certain occasions.

Yeah a very deep and useful application to communicate with all those random russians writing in the csgo chat, not knowing that noone will understand them.

Just to be clear: I made this for fun, and not to make fun of anybody or anything.

As I did the last time, here’s the sourcecode:

gist.github.com

and the binary download (Archive Password is 1234):

drive.google.com

To use the program, simply open it, set your desired keybind, and when in the csgo chat press it to generate a random sentence. The program minimizes into your system traybar.

 

Snap

How could one start off a blog better than with a .NET application on which I probably spent at most three hours.

Well, that’s all. There’s two versions, one that runs in the background and one that on start up let’s you select a screen region and uploads it to imgur.com. There’s literally nothing besides that.

I think it has some issues with multiple monitors. *Maybe* I’ll bother looking into that.

Anyway have some links

Github project

Download (Requires >= .NET 4.0)