{"id":28,"date":"2008-05-27T22:08:48","date_gmt":"2008-05-27T20:08:48","guid":{"rendered":"http:\/\/www.daniel-ritter.de\/blog\/?p=28"},"modified":"2024-05-13T01:15:41","modified_gmt":"2024-05-12T23:15:41","slug":"linux-kostenzahler-fur-umts-verbindungen","status":"publish","type":"post","link":"https:\/\/www.daniel-ritter.de\/blog\/linux-kostenzahler-fur-umts-verbindungen\/","title":{"rendered":"Linux Kostenz\u00e4hler f\u00fcr UMTS-Verbindungen"},"content":{"rendered":"<p>Ich habe ein kleines Script geschrieben um den Traffic bei UMTS\/GPRS-Verbindungen mitzuz\u00e4hlen und die entstandenen Kosten zu berechen. Ich brauche es, da ich plane bald mit einer ALDI-Talk Prepaid-Karte zu surfen, da die Preise in meinem regul\u00e4ren Vertrag zu hoch sind. (ALDI: 0,24\u20ac pro Megabyte \/ E-PLUS-BASE 6,14\u20ac !!!!!)<\/p>\n<p>Am Besten packt man es an das Ende seines Einwahlskriptes, so dass es sofort nach dem Verbindungsaufbau beginnt mitzuz\u00e4hlen.<\/p>\n<p>Alles ohne Gew\u00e4hr&#8230;. weiss nicht ob es verbugt ist oder so, also Benutzung auf eigene Gefahr <img decoding=\"async\" class=\"smiley\" title=\";)\" src=\"http:\/\/forum.ubuntuusers.de\/images\/smiles\/icon_wink.png\" alt=\";)\" \/> Bei mir mit BASE k\u00f6nnte das sehr teuer werden, also Vorsicht!<\/p>\n<pre>\r\n<strong>#!\/bin\/bash<\/strong>\r\n\r\n<strong># trafficcount - Zeigt Trafficdaten f\u00fcr die aktuelle Verbindung an und\r\n# erechnet Kosten f\u00fcr die Verbindung\r\n<\/strong>\r\n\r\n<strong># CONFIG:<\/strong>\r\n\r\n<strong># Netzwerkkarte der Verbindung\r\nINTERFACE=eth0<\/strong>\r\n\r\n<strong># Kosten pro 1 MB Traffic\r\nPREIS_PRO_MB=0.24<\/strong>\r\n\r\n<strong># Updateinterval in Sek\r\nUPDATEINTERVAL=5<\/strong>\r\n\r\n<strong>############################################<\/strong>\r\n\r\n<strong># Errechnet MB aus Byte\r\ncalc_mb()\r\n{\r\nBYTES=$1\r\nMEGABYTES=`echo \"scale=2; $BYTES \/ 1048576\" | bc`\r\n#echo \"*** $MEGABYTES ***\"\r\n}<\/strong>\r\n\r\n<strong># Holt Trafficdaten aus ifconfig\r\nget_data()\r\n{\r\n# RX bytes:3435333852 (3.1 GiB)  TX bytes:1233166424 (1.1 GiB)\r\nTRAFFICCUT=`ifconfig $INTERFACE | grep \"RX bytes\"`<\/strong>\r\n\r\n<strong>#Recieved cutten\r\nTMP=`echo $TRAFFICCUT | cut -d: -f2`\r\nIN=`echo $TMP | cut -d\" \" -f1`<\/strong>\r\n\r\n<strong># SENT cutten\r\nTMP=`echo $TRAFFICCUT | cut -d: -f3`\r\nOUT=`echo $TMP | cut -d\" \" -f1`<\/strong>\r\n\r\n<strong># TOTAL ERRECHNEN\r\nTOTAL=`echo \"$IN + $OUT\" | bc`\r\n}<\/strong>\r\n\r\n<strong>S_TOTAL=0\r\nS_IN=0\r\nS_OUT=0<\/strong>\r\n\r\n<strong>get_data\r\nSTART_TOTAL=$TOTAL\r\nSTART_IN=$IN\r\nSTART_OUT=$OUT<\/strong>\r\n\r\n<strong>#echo $START_TOTAL\r\n#echo $START_IN\r\n#echo $START_OUT<\/strong>\r\n\r\n<strong>clear<\/strong>\r\n\r\n<strong>while [ 1 ]\r\ndo<\/strong>\r\n\r\n<strong>get_data<\/strong>\r\n\r\n<strong># Aktuellen Traffic in der Sitzung bestimmen\r\nS_TOTAL=`echo \"$TOTAL - $START_TOTAL\" | bc`<\/strong>\r\n\r\n<strong>#echo \"*** S_TOTAL: $S_TOTAL ***\"<\/strong>\r\n\r\n<strong>S_IN=`echo \"$IN - $START_IN\" | bc`\r\nS_OUT=`echo \"$OUT - $START_OUT\" | bc`<\/strong>\r\n\r\n<strong># in MB umwandeln\r\ncalc_mb $TOTAL; TOTAL=$MEGABYTES\r\ncalc_mb $IN; IN=$MEGABYTES\r\ncalc_mb $OUT; OUT=$MEGABYTES\r\ncalc_mb $S_OUT; S_OUT=$MEGABYTES\r\ncalc_mb $S_IN; S_IN=$MEGABYTES\r\ncalc_mb $S_TOTAL; S_TOTAL=$MEGABYTES<\/strong>\r\n\r\n<strong># Kosten ermitteln\r\nKOSTEN=`echo \"scale=2; $S_TOTAL * $PREIS_PRO_MB \" | bc`\r\n#echo \"*** $KOSTEN - $S_TOTAL - $PREIS_PRO_MB***\"<\/strong>\r\n\r\n<strong># Sitzungsdaten updaten<\/strong>\r\n\r\n<strong>#echo $TRAFFICCUT\r\n#echo\r\necho \"GESAMT  an $INTERFACE: In: $IN MB | Out: $OUT MB | Total: $TOTAL MB \"\r\necho \"SITZUNG an $INTERFACE: In: $S_IN MB | Out: $S_OUT MB | Total: $S_TOTAL MB \"\r\necho \"KOSTEN: Euro $KOSTEN\"<\/strong>\r\n\r\n<strong>sleep $UPDATEINTERVAL\r\nclear<\/strong>\r\n\r\n<strong>done<\/strong>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Script zur Errechnung von Kosten bei UMTS-Verbindungen<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[227],"tags":[12],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-linux","tag-umts"],"_links":{"self":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":3,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":1925,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions\/1925"}],"wp:attachment":[{"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.daniel-ritter.de\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}