Nie jesteś zalogowany.
Jeśli nie posiadasz konta, zarejestruj je już teraz! Pozwoli Ci ono w pełni korzystać z naszego serwisu. Spamerom dziękujemy!
Prosimy o pomoc dla małej Julki — przekaż 1% podatku na Fundacji Dzieciom zdazyć z Pomocą.
Więcej informacji na dug.net.pl/pomagamy/.
zaczynam dopiero z C# napisalem program do pingowania z tutoriala. O to jego kod:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net.NetworkInformation; using System.Net; namespace testnetu { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { if (textBox2.Text != String.Empty) if (textBox2.Text.Trim().Length > 0) { listBox2.Items.Add(textBox2.Text); textBox2.Clear(); } } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" || listBox2.Items.Count > 0) { PingOptions opcje = new PingOptions(); opcje.Ttl = (int)numericUpDown2.Value; opcje.DontFragment = true; string dane = "aaaaaaaaa"; byte[] bufor = Encoding.ASCII.GetBytes(dane); int timeout = 120; if (textBox1.Text != "") { for (int i = 0; i < (int)numericUpDown1.Value; i++) listBox1.Items.Add(this.sprawdznet(host, timeout, bufor, opcje)); listBox1.Items.Add("---------------------"); } if (listBox2.Items.Count > 0) { foreach (string host in listBox2.Items) { for (int i = 0; i < (int)numericUpDown1.Value; i++) listBox1.Items.Add(this.sprawdznet(host, timeout, bufor, opcje)); listBox1.Items.Add("-------------------"); } } } else { MessageBox.Show("Nie wpowadzono adresów", "bład"); } } private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { if (listBox2.SelectedIndex != -1) listBox2.Items.RemoveAt(listBox2.SelectedIndex); } private String sprawdznet(string adres, int timeout, byte[] bufor, PingOptions opcje) { Ping ping = new Ping(); try { PingReply odpowiedz = ping.Send(adres, timeout, bufor, opcje); if (odpowiedz.Status == IPStatus.Success) return "Odpowidz z " + adres + " bajtów=" + odpowiedz.Buffer.Length + " czas=" + odpowiedz.RoundtripTime + "ms TTL=" + odpowiedz.Options.Ttl; else return "Błąd:" + adres + " " + odpowiedz.Status.ToString(); } catch(Exception ex) { return "błąd" + adres + " " + ex.Message; } } } }
Ale przy kompilacji wyskauj mi taki błąd :
Error 1 The name 'host' does not exist in the current context
wiecie moze co jest przyczyna?
Offline
Tak jak mówi błąd zmienna "host" nie jest znana w zaznaczonym miejscu. Definiujesz ją dopiero później i do tego w ograniczonym zasięgu pętli foreach.
if (textBox1.Text != "") { for (int i = 0; i < (int)numericUpDown1.Value; i++) listBox1.Items.Add(this.sprawdznet(host, timeout, bufor, opcje)); <---- TU listBox1.Items.Add("---------------------"); } if (listBox2.Items.Count > 0)
Ostatnio edytowany przez kamikaze (2011-02-11 16:02:55)
Offline
Time (s) | Query |
---|---|
0.00013 | SET CHARSET latin2 |
0.00005 | SET NAMES latin2 |
0.00200 | SELECT u.*, g.*, o.logged FROM punbb_users AS u INNER JOIN punbb_groups AS g ON u.group_id=g.g_id LEFT JOIN punbb_online AS o ON o.ident='3.144.123.24' WHERE u.id=1 |
0.00109 | REPLACE INTO punbb_online (user_id, ident, logged) VALUES(1, '3.144.123.24', 1732256774) |
0.00053 | SELECT * FROM punbb_online WHERE logged<1732256474 |
0.00096 | DELETE FROM punbb_online WHERE ident='18.117.71.213' |
0.00077 | DELETE FROM punbb_online WHERE ident='18.188.154.238' |
0.00076 | DELETE FROM punbb_online WHERE ident='3.135.205.26' |
0.00070 | DELETE FROM punbb_online WHERE ident='3.141.7.165' |
0.00070 | DELETE FROM punbb_online WHERE ident='3.17.166.157' |
0.00088 | SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 FROM punbb_topics AS t INNER JOIN punbb_forums AS f ON f.id=t.forum_id LEFT JOIN punbb_forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=18297 AND t.moved_to IS NULL |
0.00006 | SELECT search_for, replace_with FROM punbb_censoring |
0.00123 | SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM punbb_posts AS p INNER JOIN punbb_users AS u ON u.id=p.poster_id INNER JOIN punbb_groups AS g ON g.g_id=u.group_id LEFT JOIN punbb_online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id=18297 ORDER BY p.id LIMIT 0,25 |
0.00086 | UPDATE punbb_topics SET num_views=num_views+1 WHERE id=18297 |
Total query time: 0.01072 s |