<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>j-zero&#187; j-zero.de</title>
	<atom:link href="http://www.j-zero.de/blog/tag/bash/feed" rel="self" type="application/rss+xml" />
	<link>http://www.j-zero.de</link>
	<description>Leben. Computer. Rock &#039;n&#039; Roll.</description>
	<lastBuildDate>Mon, 05 Jul 2010 11:53:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ping auf einen TCP-Port</title>
		<link>http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html</link>
		<comments>http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html#comments</comments>
		<pubDate>Tue, 12 May 2009 13:28:04 +0000</pubDate>
		<dc:creator>j-zero</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Netzwerk]]></category>

		<guid isPermaLink="false">http://www.j-zero.de/?p=222</guid>
		<description><![CDATA[Mahlzeit, wie von schmidt24 schon angekündigt habe ich das tcpping-Skript ein wenig erweitert, da ich finde, das Timeouts nicht markant genug dargestellt wurden, habe ich diese in rot und erfolgreiche Pings durch ein grünes &#8220;ok&#8221; markiert. Zudem ist es nun möglich, anstatt des Ports den Namen aus der /etc/services anzugeben (falls man z.B. mal den [...]]]></description>
			<content:encoded><![CDATA[<p>Mahlzeit,</p>
<p>wie von <a href="http://www.schmidt24.org/blog/2009/05/12/ping-auf-einen-tcp-port/" target="_blank">schmidt24</a> schon angekündigt habe ich das tcpping-Skript ein wenig erweitert, da ich finde, das Timeouts nicht markant genug dargestellt wurden, habe ich diese in rot und erfolgreiche Pings durch ein grünes &#8220;ok&#8221; markiert.</p>
<p>Zudem ist es nun möglich, anstatt des Ports den Namen aus der /etc/services anzugeben (falls man z.B. mal den Port von IMAPS nicht im Kopf hat).</p>
<p>Beispiel: &#8220;tcpping.sh 127.0.0.1 imaps&#8221; ist equivalent zu &#8220;tcpping.sh l27.0.0.1 993&#8243;.<br />
Der Standardport ist auch nun 22, also SSH da dieser ja meist auf Linux/UN*X Maschinen auf ist.<br />
Man kann also einfach &#8220;tcpping.sh 127.0.0.1&#8243; nutzen und es wird automatisch auf SSH geprüft.<br />
Die Namens- und Portauflösung sind nur eine nette Spielerei aber für den ein oder anderen Skripter vielleicht ganz nützlich. <img src='http://www.j-zero.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hier ist es:</p>
<div class="codecolorer-container bash geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/sh</span><br />
<br />
<span style="color: #007800;">i</span>=<span style="color: #000000;">0</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #007800;">PORT</span>=<span style="color: #000000;">22</span><br />
<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #007800;">PORT</span>=<span style="color: #007800;">$2</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> &nbsp;<span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: $0 &lt;HOST&gt; [PORT]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &nbsp; PORT can be numeric or name from /etc/services&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &nbsp; Default port is 22 (ssh)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$1.&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;([0-9]{1,3}\.){4}&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #007800;">HOST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>host <span style="color: #660033;">-v</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-1</span> <span style="color: #660033;">-m1</span> &nbsp;<span style="color: #660033;">-A1</span> <span style="color: #ff0000;">&quot;;; ANSWER SECTION&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> NF <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\.$//'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">IP</span>=<span style="color: #007800;">$1</span><br />
<span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #007800;">IP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>host <span style="color: #660033;">-v</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-A1</span> <span style="color: #ff0000;">&quot;;; ANSWER SECTION&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> NF <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\.$//'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">HOST</span>=<span style="color: #007800;">$1</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$PORT</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">0</span>-<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp;<span style="color: #007800;">PORT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>services <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">1</span> <span style="color: #007800;">$PORT</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/\/tcp//g&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span><br />
<br />
<span style="color: #007800;">PROTO</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>services <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">1</span> <span style="color: #007800;">$PORT</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/\/tcp//g&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">true</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">TIME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">%</span>N<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c</span> -<span style="color: #000000;">13</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">SCAN</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">nmap</span> <span style="color: #660033;">-P0</span> -p<span style="color: #007800;">$PORT</span> <span style="color: #007800;">$1</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$SCAN</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-q</span> open<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;tcp ping from <span style="color: #007800;">$HOST</span> (<span style="color: #007800;">$IP</span>) port <span style="color: #007800;">$PORT</span> (<span style="color: #007800;">$PROTO</span>): tcp_seq=<span style="color: #007800;">$i</span> time=<span style="color: #007800;">$(($((`date +%s%N| cut -c -13`-$TIME)</span>)))ms<span style="color: #000099; font-weight: bold;">\t</span>[\033[1;31mtimeout\033[0m]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;tcp ping from <span style="color: #007800;">$HOST</span> (<span style="color: #007800;">$IP</span>) port <span style="color: #007800;">$PORT</span> (<span style="color: #007800;">$PROTO</span>): tcp_seq=<span style="color: #007800;">$i</span> time=<span style="color: #007800;">$(($((`date +%s%N| cut -c -13`-$TIME)</span>)))ms<span style="color: #000099; font-weight: bold;">\t</span>[\033[1;32mok\033[0m]&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">i</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>i+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">done</span></div></td></tr></tbody></table></div>
<p>viel spaß und erfolg damit.</p>
<p><strong>Known Bugs:</strong></p>
<ul>
<li>Wenn als Host ein Nmap Parameter übergeben wird wie z.B: &#8220;&#8211;help&#8221; ist der Ping &#8220;[ok]&#8220;, da Nmap die Hilfe ausgibt, &#8220;grep -q open&#8221; ist in dem Fall Wahr, da auch in der Help ein &#8220;open&#8221; vorkommt.</li>
<li>Die Domainauflösung zur IP funktioniert zurzeit nicht bei einem Alias, da dann als erstes Ergebnis von &#8220;host&#8221; der CNAME zurückgeliefert wird.</li>
</ul>
<p>Wenn jemand eine Idee hat, wie das zu lösen ist (bevor ich eine habe oder das ganze Ding in Perl implementiere) wäre ich dankbar.</p>
<p>bis neulich</p>
<p>j-zero</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-spaced shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-printfriendly">
			<a href="http://www.printfriendly.com/print?url=http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html" rel="nofollow" class="external" title="Sende diese Seite zu Print Friendly">Sende diese Seite zu Print Friendly</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Ping%20auf%20einen%20TCP-Port%22&amp;body=Link: http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html (sent via shareaholic)%0D%0A%0D%0A----%0D%0A Mahlzeit%2C%0D%0A%0D%0Awie%20von%20schmidt24%20schon%20angek%C3%BCndigt%20habe%20ich%20das%20tcpping-Skript%20ein%20wenig%20erweitert%2C%20da%20ich%20finde%2C%20das%20Timeouts%20nicht%20markant%20genug%20dargestellt%20wurden%2C%20habe%20ich%20diese%20in%20rot%20und%20erfolgreiche%20Pings%20durch%20ein%20gr%C3%BCnes%20%22ok%22%20markiert.%0D%0A%0D%0AZudem%20ist%20es%20nun%20m%C3%B6glich%2C%20anstatt%20des%20Ports%20den%20Name" rel="nofollow" class="external" title="Sende diesen Artikel einem Freund per Email">Sende diesen Artikel einem Freund per Email</a>
		</li>
		<li class="shr-comfeed">
			<a href="http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html/feed" rel="nofollow" class="external" title="Abonniere die Kommentare für diesen Beitrag">Abonniere die Kommentare für diesen Beitrag</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html&amp;title=Ping+auf+einen+TCP-Port" rel="nofollow" class="external" title="Empfehle diesen Artikel bei SlashDot">Empfehle diesen Artikel bei SlashDot</a>
		</li>
		<li class="shr-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html&amp;title=Ping+auf+einen+TCP-Port" rel="nofollow" class="external" title="Füge hinzu zu Google Bookmarks">Füge hinzu zu Google Bookmarks</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html&amp;title=Ping+auf+einen+TCP-Port" rel="nofollow" class="external" title="Empfehle diesen Artikel bei del.icio.us">Empfehle diesen Artikel bei del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html&amp;title=Ping+auf+einen+TCP-Port" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-googlereader">
			<a href="http://www.google.com/reader/link?url=http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html&amp;title=Ping+auf+einen+TCP-Port&amp;srcUrl=http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html&amp;srcTitle=Ping+auf+einen+TCP-Port&amp;snippet=Mahlzeit%2C%0D%0A%0D%0Awie%20von%20schmidt24%20schon%20angek%C3%BCndigt%20habe%20ich%20das%20tcpping-Skript%20ein%20wenig%20erweitert%2C%20da%20ich%20finde%2C%20das%20Timeouts%20nicht%20markant%20genug%20dargestellt%20wurden%2C%20habe%20ich%20diese%20in%20rot%20und%20erfolgreiche%20Pings%20durch%20ein%20gr%C3%BCnes%20%22ok%22%20markiert.%0D%0A%0D%0AZudem%20ist%20es%20nun%20m%C3%B6glich%2C%20anstatt%20des%20Ports%20den%20Name" rel="nofollow" class="external" title="Füge hinzu zu Google Reader">Füge hinzu zu Google Reader</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Ping+auf+einen+TCP-Port+-+http://tinyurl.com/2a2jf6m&amp;source=shareaholic" rel="nofollow" class="external" title="Twittere diesen Artikel!">Twittere diesen Artikel!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.j-zero.de/blog/ping-auf-einen-tcp-port-222.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
